Module: Card::Set::All::Type

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod002-core/all/type.rb

Overview

Set: All cards (Type)

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/type.rb"; end

Instance Method Details

#event: validate_typeObject



62
63
64
65
66
67
68
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 62

event :validate_type, :validate, changed: :type_id, on: :save do
  errors.add :type, tr(:error_no_such_type) unless type_name

  if (rt = structure) && rt.assigns_type? && type_id != rt.type_id
    errors.add :type, tr(:error_hard_templated, name: name, type_name: rt.type_name)
  end
end

#event: validate_type_changeObject



52
53
54
55
56
57
58
59
60
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 52

event :validate_type_change, :validate, on: :update, changed: :type_id do
  if (c = dup) && c.action == :create && !c.valid?
    errors.add :type, tr(
      :error_cant_change_errors,
      name: name, type_id: type_id,
      error_messages: c.errors.full_messages
    )
  end
end

#type=(type_name) ⇒ Object



38
39
40
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 38

def type= type_name
  self.type_id = Card.fetch_id type_name
end

#type_cardObject



15
16
17
18
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 15

def type_card
  return if type_id.nil?
  Card.quick_fetch type_id.to_i
end

#type_cardnameObject



34
35
36
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 34

def type_cardname
  type_card.try :name
end

#type_codeObject



20
21
22
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 20

def type_code
  Card::Codename[type_id.to_i]
end

#type_id=(card_or_id) ⇒ Object



42
43
44
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 42

def type_id= card_or_id
  write_card_or_id :type_id, card_or_id
end

#type_id_from_templateObject



46
47
48
49
50
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 46

def type_id_from_template
  return unless name && (t = template)
  reset_patterns # still necessary even with new template handling?
  self.type_id = t.type_id
end

#type_nameObject Also known as: type



24
25
26
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 24

def type_name
  type_card.try :name
end

#type_name_or_defaultObject



30
31
32
# File 'card/tmpsets/set/mod002-core/all/type.rb', line 30

def type_name_or_default
  type_card.try(:name) || Card.quick_fetch(Card.default_type_id).name
end