Module: Card::Set::All::Subcards

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

Overview

Set: All cards (Subcards)

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/subcards.rb', line 7

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

Instance Method Details

#add_subcard(name_or_card, args = {}) ⇒ Object Also known as: attach_subcard

phase_method :attach_subcard, before: :store do |name_or_card, args=nil| TODO: handle differently in different stages



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

def add_subcard name_or_card, args={}
  subcards.add name_or_card, args
end

#add_subcard!(name_or_card, args = {}) ⇒ Object Also known as: attach_subcard!



43
44
45
46
47
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 43

def add_subcard! name_or_card, args={}
  subcard = subcards.add name_or_card, args
  subcard.director.reset_stage
  subcard
end

#attach_subfield(name_or_card, args = {}) ⇒ Object Also known as: add_subfield

phase_method :attach_subfield, before: :approve do name_or_card, args=nil


51
52
53
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 51

def attach_subfield name_or_card, args={}
  subcards.add_field name_or_card, args
end

#attach_subfield!(name_or_card, args = {}) ⇒ Object



56
57
58
59
60
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 56

def attach_subfield! name_or_card, args={}
  subcard = subcards.add_field name_or_card, args
  subcard.director.reset_stage
  subcard
end

#clear_subcardsObject



72
73
74
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 72

def clear_subcards
  subcards.clear
end

#deep_clear_subcardsObject



90
91
92
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 90

def deep_clear_subcards
  subcards.deep_clear
end

#detach_subcard(name_or_card) ⇒ Object Also known as: remove_subcard



62
63
64
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 62

def detach_subcard name_or_card
  subcards.remove name_or_card
end

#detach_subfield(name_or_card) ⇒ Object Also known as: remove_subfield



67
68
69
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 67

def detach_subfield name_or_card
  subcards.remove_field name_or_card
end

#ensure_subfield(field_name, args = {}) ⇒ Object

ensures subfield is present does NOT override subfield content if already present



78
79
80
81
82
83
84
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 78

def ensure_subfield field_name, args={}
  if subfield_present? field_name
    subfield field_name
  else
    add_subfield field_name, args
  end
end

#event: reject_empty_subcardsObject



109
110
111
112
113
114
115
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 109

event :reject_empty_subcards, :prepare_to_validate do
  subcards.each_with_key do |subcard, key|
    next unless subcard.new? && subcard.unfilled?
    remove_subcard(key)
    director.subdirectors.delete(subcard)
  end
end

#expire_subcardsObject



32
33
34
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 32

def expire_subcards
  subcards.clear
end

#field(tag, opts = {}) ⇒ Object



8
9
10
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 8

def field tag, opts={}
  Card.fetch name.field(tag), opts
end

#field?(tag) ⇒ Boolean

Returns:

  • (Boolean)


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

def field? tag
  field(tag) || subfield(tag)
end

#handle_subcard_errorsObject



94
95
96
97
98
99
100
101
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 94

def handle_subcard_errors
  subcards.each do |subcard|
    subcard.errors.each do |error|
      subcard_error subcard, error
    end
    subcard.errors.clear
  end
end

#same_field?Boolean

check when renaming field that it is not actually the same field (eg on a renamed trunk)

Returns:

  • (Boolean)


125
126
127
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 125

def same_field?
  (left_id == left_id_before_act) && (right_id == right_id_before_act)
end

#subcard(card_name) ⇒ Object



12
13
14
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 12

def subcard card_name
  subcards.card card_name
end

#subcard_error(subcard, error) ⇒ Object



103
104
105
106
107
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 103

def subcard_error subcard, error
  msg = error.message
  msg = "#{error.attribute} #{msg}" unless %i[content abort].member? error.attribute
  errors.add subcard.name.from(name), msg
end

#subcardsObject



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

def subcards
  @subcards ||= Card::Subcards.new self
end

#subcards?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 28

def subcards?
  subcards.present?
end

#subfield(field_name) ⇒ Object



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

def subfield field_name
  subcards.field field_name
end

#subfield_present?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 86

def subfield_present? field_name
  subfield(field_name)&.content&.present?
end

#trashed_left?Boolean

check when deleting field that left has not also been deleted

Returns:

  • (Boolean)


118
119
120
121
# File 'card/tmpsets/set/mod002-core/all/subcards.rb', line 118

def trashed_left?
  l = left
  !l || l.trash
end