card 1.103.4 → 1.104.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/environments/development.rb +4 -2
  4. data/config/environments/test.rb +1 -1
  5. data/config/initializers/01_core_extensions/array.rb +4 -1
  6. data/config/initializers/01_core_extensions/object.rb +1 -1
  7. data/config/initializers/02_patches/active_record.rb +16 -17
  8. data/config/locales/de.yml +8 -564
  9. data/config/locales/es.yml +2 -3
  10. data/db/migrate/20110511221913_require_earlier_migrations.rb +1 -1
  11. data/db/migrate/20120105203350_require_1_8_migrations.rb +1 -1
  12. data/db/migrate/20121111025347_require_1_10_migrations.rb +1 -1
  13. data/db/migrate/20211128040849_virtuals_updated_at.rb +11 -0
  14. data/db/migrate_core_cards/20190502130029_add_shark_and_help_desk_role.rb +0 -1
  15. data/db/schema.rb +19 -16
  16. data/db/seed/new/card_actions.yml +1323 -2091
  17. data/db/seed/new/card_acts.yml +2 -2
  18. data/db/seed/new/card_references.yml +629 -741
  19. data/db/seed/new/cards.yml +2593 -5557
  20. data/db/seed/new/schema_migrations.yml +2 -0
  21. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  22. data/db/seed/test/fixtures/card_actions.yml +2555 -3395
  23. data/db/seed/test/fixtures/card_acts.yml +606 -666
  24. data/db/seed/test/fixtures/card_changes.yml +101 -101
  25. data/db/seed/test/fixtures/card_references.yml +1609 -1686
  26. data/db/seed/test/fixtures/cards.yml +4363 -7541
  27. data/db/seed/test/fixtures/schema_migrations.yml +2 -0
  28. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  29. data/db/test_seed.rb +1 -4
  30. data/db/version.txt +1 -1
  31. data/db/version_core_cards.txt +1 -1
  32. data/lib/card/auth/current.rb +1 -1
  33. data/lib/card/auth/permissions.rb +37 -35
  34. data/lib/card/content/all.rb +3 -3
  35. data/lib/card/content/chunk.rb +1 -0
  36. data/lib/card/director/act_direction.rb +1 -3
  37. data/lib/card/director/card_methods.rb +0 -1
  38. data/lib/card/director/phases.rb +1 -0
  39. data/lib/card/director.rb +1 -0
  40. data/lib/card/fetch/all.rb +3 -3
  41. data/lib/card/fetch/card_class.rb +5 -11
  42. data/lib/card/fetch/results.rb +2 -2
  43. data/lib/card/model/save_helper.rb +2 -2
  44. data/lib/card/name/all/descendants.rb +9 -7
  45. data/lib/card/name/all/parts.rb +1 -1
  46. data/lib/card/name/all.rb +4 -3
  47. data/lib/card/name/card_class.rb +1 -0
  48. data/lib/card/name/fields_and_traits.rb +6 -30
  49. data/lib/card/name/name_variants.rb +5 -1
  50. data/lib/card/name.rb +0 -8
  51. data/lib/card/query/abstract_query/tie.rb +2 -3
  52. data/lib/card/query/card_query/normalization.rb +1 -1
  53. data/lib/card/query/sql_statement/order.rb +5 -6
  54. data/lib/card/query/value.rb +10 -7
  55. data/lib/card/reference/all.rb +9 -7
  56. data/lib/card/reference.rb +36 -41
  57. data/lib/card/rule/all.rb +3 -3
  58. data/lib/card/set/advanced_api.rb +5 -0
  59. data/lib/card/set/event/delayed_event.rb +8 -1
  60. data/lib/card/set/event.rb +1 -0
  61. data/lib/card/set/helpers.rb +30 -17
  62. data/lib/card/set/pattern/all.rb +13 -4
  63. data/lib/card/set/pattern/base.rb +12 -18
  64. data/lib/card/set/pattern/class_methods.rb +13 -13
  65. data/lib/card/set/pattern.rb +30 -19
  66. data/lib/card/set/trait.rb +16 -1
  67. data/lib/card/set/type.rb +3 -0
  68. data/lib/card/subcards/add.rb +1 -3
  69. data/lib/card/subcards/all.rb +30 -56
  70. data/lib/card/view/options.rb +7 -5
  71. data/lib/cardio/cli.rb +1 -0
  72. data/lib/cardio/commands/custom.rb +60 -0
  73. data/lib/cardio/commands/rake_command/parser.rb +49 -48
  74. data/lib/cardio/commands/rake_command.rb +17 -15
  75. data/lib/cardio/commands/rspec_command.rb +2 -0
  76. data/lib/cardio/commands.rb +69 -69
  77. data/lib/cardio/generators.rb +56 -3
  78. data/lib/cardio/migration/deck.rb +0 -0
  79. data/lib/cardio/migration/deck_structure.rb +2 -0
  80. data/lib/cardio/migration/import/import_data/card_content.rb +1 -1
  81. data/lib/cardio/migration/import.rb +2 -2
  82. data/lib/cardio/migration.rb +26 -2
  83. data/lib/cardio/mod/class_methods.rb +112 -0
  84. data/lib/cardio/mod/dirs.rb +15 -11
  85. data/lib/cardio/mod/eat/edibles.rb +92 -0
  86. data/lib/cardio/mod/eat.rb +81 -0
  87. data/lib/cardio/mod/load_strategy/tmp_files.rb +1 -1
  88. data/lib/cardio/mod/modfile_api.rb +5 -0
  89. data/lib/cardio/mod/poop.rb +135 -0
  90. data/lib/cardio/mod.rb +20 -80
  91. data/lib/cardio/railtie.rb +15 -3
  92. data/lib/cardio/schema.rb +11 -10
  93. data/lib/cardio/version.rb +35 -0
  94. data/lib/cardio.rb +4 -0
  95. data/lib/generators/deck/templates/Gemfile.erb +0 -4
  96. data/lib/generators/deck/templates/rspec.erb +1 -1
  97. data/lib/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -1
  98. data/lib/generators/mod/USAGE +1 -0
  99. data/lib/tasks/card/migrate.rake +41 -1
  100. data/lib/tasks/card/mod.rake +15 -8
  101. data/lib/tasks/card.rake +47 -87
  102. data/mod/admin/locales/de.yml +4 -0
  103. data/mod/admin/set/self/admin.rb +10 -8
  104. data/mod/core/data/production.yml +7 -0
  105. data/mod/core/data/test.yml +30 -0
  106. data/mod/core/locales/de.yml +28 -0
  107. data/mod/core/set/all/assign_attributes.rb +1 -33
  108. data/mod/core/set/all/content.rb +3 -1
  109. data/mod/core/set/all/initialize.rb +1 -4
  110. data/mod/core/set/all/name_events.rb +3 -18
  111. data/mod/core/set/all/reference_events.rb +29 -28
  112. data/mod/core/set/all/subcards.rb +6 -2
  113. data/mod/core/set/all/trash.rb +2 -3
  114. data/mod/core/set/all/type.rb +67 -18
  115. data/mod/core/set/self/version.rb +1 -1
  116. data/mod/core/spec/set/self/trash_spec.rb +1 -1
  117. data/mod/standard/{file → data/files}/favicon/image-icon.png +0 -0
  118. data/mod/standard/{file → data/files}/favicon/image-large.png +0 -0
  119. data/mod/standard/{file → data/files}/favicon/image-medium.png +0 -0
  120. data/mod/standard/{file → data/files}/favicon/image-original.png +0 -0
  121. data/mod/standard/{file → data/files}/favicon/image-small.png +0 -0
  122. data/mod/standard/{file → data/files}/logo/image-original.svg +0 -0
  123. metadata +37 -28
  124. data/db/migrate_core_cards/20150605115802_add_performance_log_card.rb +0 -7
  125. data/lib/card/set/code_nest.rb +0 -15
  126. data/lib/card/version.rb +0 -11
  127. data/lib/cardio/commands/USAGE +0 -28
  128. data/lib/cardio/generators/class_methods.rb +0 -35
  129. data/lib/tasks/card/asset.rake +0 -22
  130. data/mod/core/spec/set/all/clean_me_spec.rb +0 -258
  131. data/mod/core/spec/set/all/export_spec.rb +0 -71
  132. data/tmpsets/set_pattern/100-all.rb +0 -22
  133. data/tmpsets/set_pattern/101-all_plus.rb +0 -24
  134. data/tmpsets/set_pattern/102-type.rb +0 -40
  135. data/tmpsets/set_pattern/103-star.rb +0 -26
  136. data/tmpsets/set_pattern/104-rstar.rb +0 -28
  137. data/tmpsets/set_pattern/105-rule.rb +0 -28
  138. data/tmpsets/set_pattern/106-right.rb +0 -35
  139. data/tmpsets/set_pattern/107-type_plus_right.rb +0 -43
  140. data/tmpsets/set_pattern/108-self.rb +0 -34
@@ -4,17 +4,21 @@ class Card
4
4
  # a Reference is a directional relationship from one card (the referer)
5
5
  # to another (the referee).
6
6
  class Reference < Cardio::Record
7
+ # card that refers
8
+ def referer
9
+ Card[referer_id]
10
+ end
11
+
12
+ # card that is referred to
13
+ def referee
14
+ Card[referee_id]
15
+ end
16
+
7
17
  class << self
8
18
  # bulk insert improves performance considerably
9
19
  # array takes form [ [referer_id, referee_id, referee_key, ref_type], ...]
10
20
  def mass_insert array
11
- return if array.empty?
12
-
13
- value_statements = array.map { |values| "\n(#{values.join ', '})" }
14
- sql = "INSERT into card_references "\
15
- "(referer_id, referee_id, referee_key, ref_type) "\
16
- "VALUES #{value_statements.join ', '}"
17
- Card.connection.execute sql
21
+ Card.connection.execute mass_insert_sql(array) if array.present?
18
22
  end
19
23
 
20
24
  # map existing reference to name to card via id
@@ -27,22 +31,10 @@ class Card
27
31
  where(referee_id: referee_id).update_all referee_id: nil
28
32
  end
29
33
 
30
- # find all references to missing (eg deleted) cards and reset them
31
- def unmap_if_referee_missing
32
- joins(
33
- "LEFT JOIN cards ON card_references.referee_id = cards.id"
34
- ).where(
35
- "(cards.id IS NULL OR cards.trash IS TRUE) AND referee_id IS NOT NULL"
36
- ).update_all referee_id: nil
37
- end
38
-
39
- # remove all references from missing (eg deleted) cards
40
- def delete_if_referer_missing
41
- joins(
42
- "LEFT JOIN cards ON card_references.referer_id = cards.id"
43
- ).where(
44
- "cards.id IS NULL"
45
- ).pluck_in_batches(:id) do |group_ids|
34
+ # remove reference to and from missing cards
35
+ def clean
36
+ missing(:referee_id).where("referee_id IS NOT NULL").update_all referee_id: nil
37
+ missing(:referer_id).pluck_in_batches(:id) do |group_ids|
46
38
  # used to be .delete_all here, but that was failing on large dbs
47
39
  Rails.logger.info "deleting batch of references"
48
40
  where("id in (#{group_ids.join ','})").delete_all
@@ -52,34 +44,37 @@ class Card
52
44
  # repair references one by one (delete, create, delete, create...)
53
45
  # slower, but better than #recreate_all for use on running sites
54
46
  def repair_all
55
- delete_if_referer_missing
56
- Card.where(trash: false).find_each do |card|
57
- Rails.logger.info "updating references from #{card}"
58
- card.include_set_modules
59
- card.update_references_out
60
- end
47
+ clean
48
+ each_card(&:update_references_out)
61
49
  end
62
50
 
63
51
  # delete all references, then recreate them one by one
64
52
  # faster than #repair_all, but not recommended for use on running sites
65
53
  def recreate_all
66
54
  delete_all
55
+ each_card(&:create_references_out)
56
+ end
57
+
58
+ private
59
+
60
+ # find all references to or from missing (eg deleted) cards
61
+ def missing field
62
+ joins("LEFT JOIN cards ON card_references.#{field} = cards.id")
63
+ .where("(cards.id IS NULL OR cards.trash IS TRUE)")
64
+ end
65
+
66
+ def each_card
67
67
  Card.where(trash: false).find_each do |card|
68
- Rails.logger.info "updating references from #{card}"
69
- card.include_set_modules
70
- card.create_references_out
68
+ Rails.logger.debug "references from #{card.name}"
69
+ yield card.include_set_modules
71
70
  end
72
71
  end
73
- end
74
-
75
- # card that refers
76
- def referer
77
- Card[referer_id]
78
- end
79
72
 
80
- # card that is referred to
81
- def referee
82
- Card[referee_id]
73
+ def mass_insert_sql array
74
+ value_statements = array.map { |values| "\n(#{values.join ', '})" }
75
+ "INSERT into card_references (referer_id, referee_id, referee_key, ref_type) " \
76
+ "VALUES #{value_statements.join ', '}"
77
+ end
83
78
  end
84
79
  end
85
80
  end
data/lib/card/rule/all.rb CHANGED
@@ -64,9 +64,9 @@ class Card
64
64
  end
65
65
 
66
66
  def rule_id_lookup lookup_hash, cache_suffix, fallback_suffix=nil
67
- rule_set_keys.each do |rule_set_key|
68
- rule_id = lookup_hash["#{rule_set_key}+#{cache_suffix}"]
69
- rule_id ||= fallback_suffix && lookup_hash["#{rule_set_key}+#{fallback_suffix}"]
67
+ rule_lookup_keys.each do |lookup_key|
68
+ rule_id = lookup_hash["#{lookup_key}+#{cache_suffix}"]
69
+ rule_id ||= fallback_suffix && lookup_hash["#{lookup_key}+#{fallback_suffix}"]
70
70
  return rule_id if rule_id
71
71
  end
72
72
  nil
@@ -2,6 +2,11 @@ class Card
2
2
  module Set
3
3
  # advanced set module API
4
4
  module AdvancedApi
5
+ def assign_type type, module_key=nil
6
+ module_key ||= shortname
7
+ Type.assignment[module_key] = type.card_id
8
+ end
9
+
5
10
  def setting_opts opts
6
11
  extend Card::Setting
7
12
  register_setting opts
@@ -1,7 +1,14 @@
1
1
  class Card
2
2
  # attributes that ActiveJob can handle
3
+ #
4
+ # supercard and superleft are excluded, because it caused issues to have them in
5
+ # delayed job but not fully restored (set modules not included, attributes not retained,
6
+ # etc.) Since we're supposed to have an actual _left_ by the integrate_with_delay
7
+ # stage, it's not clear that they're needed. But if we revisit and find they _are_
8
+ # needed, then we clearly need to make sure that they are fully restored. At a bare
9
+ # minimum they would need to include set modules.
3
10
  def serializable_attributes
4
- self.class.action_specific_attributes + set_specific.keys
11
+ self.class.action_specific_attributes + set_specific.keys - %i[supercard superleft]
5
12
  end
6
13
 
7
14
  module Set
@@ -168,6 +168,7 @@ class Card
168
168
  def rescuing_integration
169
169
  yield
170
170
  rescue StandardError => e
171
+ # puts "integration error: #{e.message}".red
171
172
  Card::Error.report e, self
172
173
  ensure
173
174
  true
@@ -20,7 +20,7 @@ class Card
20
20
  end
21
21
 
22
22
  def set_format_type_key
23
- :"#{set_type_key}_format"
23
+ @set_format_type_key ||= :"#{set_type_key}_format"
24
24
  end
25
25
 
26
26
  def set_type_key
@@ -64,22 +64,6 @@ class Card
64
64
  end
65
65
  end
66
66
 
67
- def format_modules format_sym
68
- type_key = set_format_type_key
69
- if !type_key || type_key == :base_format
70
- [format_module(format_sym)]
71
- elsif abstract_set?
72
- [test_set.format_module(format_sym)]
73
- else
74
- format_class = Card::Format.format_class format: format_sym
75
- Card::Set.modules[type_key][format_class][shortname] || []
76
- end
77
- end
78
-
79
- def format_module format_sym
80
- const_get Card::Format.format_class_name(format_sym)
81
- end
82
-
83
67
  def test_set
84
68
  # rubocop:disable Lint/Eval
85
69
  ::Card::Set::Self.const_remove_if_defined :TestSet
@@ -94,6 +78,35 @@ class Card
94
78
  ::Card::Set::Self::TestSet
95
79
  # rubocop:enable Lint/Eval
96
80
  end
81
+
82
+ def format_modules format_sym, test: true
83
+ if base_format_modules?
84
+ [format_module(format_sym)]
85
+ elsif abstract_set?
86
+ abstract_format_modules format_sym, test
87
+ else
88
+ nonbase_format_modules format_sym
89
+ end
90
+ end
91
+
92
+ def format_module format_sym
93
+ const_get Card::Format.format_class_name(format_sym)
94
+ end
95
+
96
+ private
97
+
98
+ def base_format_modules?
99
+ !set_format_type_key || set_format_type_key == :base_format
100
+ end
101
+
102
+ def abstract_format_modules format_sym, test
103
+ [(test ? test_set : self).format_module(format_sym)]
104
+ end
105
+
106
+ def nonbase_format_modules format_sym
107
+ format_class = Card::Format.format_class format: format_sym
108
+ Card::Set.modules[set_format_type_key][format_class][shortname] || []
109
+ end
97
110
  end
98
111
  end
99
112
  end
@@ -1,6 +1,6 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # pattern-related Card instance methods
5
5
  module All
6
6
  def patterns?
@@ -20,7 +20,7 @@ class Card
20
20
  # Rails.logger.info "resetting patterns: #{name}"
21
21
  @patterns = @concrete_patterns = nil
22
22
  @template = @virtual = nil
23
- @set_mods_loaded = @set_modules = @set_names = @rule_set_keys = nil
23
+ @set_mods_loaded = @set_modules = @set_names = @rule_lookup_keys = nil
24
24
  @junction_only = nil # only applies to set cards
25
25
  true
26
26
  end
@@ -51,13 +51,22 @@ class Card
51
51
  patterns.map(&:module_key).include? set_module.shortname
52
52
  end
53
53
 
54
- def rule_set_keys
55
- @rule_set_keys ||= patterns.map(&:rule_set_key).compact
54
+ def rule_lookup_keys
55
+ @rule_lookup_keys ||= patterns.map(&:rule_lookup_key).compact
56
56
  end
57
57
 
58
58
  def include_module? set
59
59
  singleton_class&.include? set
60
60
  end
61
+
62
+ def each_type_assigning_module_key
63
+ patterns.each do |p|
64
+ next unless p.assigns_type
65
+
66
+ module_key = p.module_key
67
+ yield module_key if module_key
68
+ end
69
+ end
61
70
  end
62
71
  end
63
72
  end
@@ -1,19 +1,21 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # class from which set patterns inherit
5
5
  class Base
6
6
  extend ClassMethods
7
+ delegate :pattern_code, :pattern, :anchorless?, :anchor_parts_count,
8
+ :assigns_type, to: :class
7
9
 
8
10
  def initialize card
9
- return if self.class.anchorless?
11
+ return if anchorless?
10
12
 
11
13
  @anchor_name = self.class.anchor_name(card).to_name
12
14
  @anchor_id = find_anchor_id card
13
15
  end
14
16
 
15
17
  def find_anchor_id card
16
- self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name)
18
+ self.class.try(:anchor_id, card) || @anchor_name.card_id
17
19
  end
18
20
 
19
21
  def module_key
@@ -53,16 +55,8 @@ class Card
53
55
  end
54
56
  end
55
57
 
56
- def anchor_parts_count
57
- self.class.anchor_parts_count
58
- end
59
-
60
- def pattern
61
- @pattern ||= self.class.pattern
62
- end
63
-
64
58
  def to_s
65
- self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
59
+ anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
66
60
  end
67
61
 
68
62
  def inspect
@@ -70,15 +64,15 @@ class Card
70
64
  end
71
65
 
72
66
  def safe_key
73
- caps_part = self.class.pattern_code.to_s.tr(" ", "_").upcase
74
- self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
67
+ caps_part = pattern_code.to_s.tr(" ", "_").upcase
68
+ anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
75
69
  end
76
70
 
77
- def rule_set_key
78
- if self.class.anchorless?
79
- self.class.pattern_code.to_s
71
+ def rule_lookup_key
72
+ if anchorless?
73
+ pattern_code.to_s
80
74
  elsif @anchor_id
81
- "#{@anchor_id}+#{self.class.pattern_code}"
75
+ "#{@anchor_id}+#{pattern_code}"
82
76
  end
83
77
  end
84
78
  end
@@ -1,10 +1,9 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # methods for Set::Pattern classes
5
5
  module ClassMethods
6
- attr_accessor :pattern_code, :pattern_id, :junction_only,
7
- :assigns_type, :anchorless
6
+ attr_accessor :pattern_code, :junction_only, :assigns_type, :anchorless
8
7
  attr_writer :anchor_parts_count
9
8
 
10
9
  def new card
@@ -12,14 +11,10 @@ class Card
12
11
  end
13
12
 
14
13
  def register pattern_code, opts={}
15
- if (self.pattern_id = Card::Codename.id(pattern_code))
16
- self.pattern_code = pattern_code
17
- Pattern.concrete.insert opts.delete(:index).to_i, self
18
- self.anchorless = !respond_to?(:anchor_name)
19
- opts.each { |key, val| send "#{key}=", val }
20
- else
21
- warn "no codename for pattern code: #{pattern_code}"
22
- end
14
+ self.pattern_code = pattern_code
15
+ Pattern.concrete.insert opts.delete(:index).to_i, self
16
+ self.anchorless = !respond_to?(:anchor_name)
17
+ opts.each { |key, val| send "#{key}=", val }
23
18
  end
24
19
 
25
20
  def junction_only?
@@ -30,8 +25,13 @@ class Card
30
25
  anchorless
31
26
  end
32
27
 
28
+ def pattern_id
29
+ pattern_code.card_id
30
+ end
31
+
32
+ # TODO: change to #name or #pattern_name
33
33
  def pattern
34
- Card.fetch(pattern_id, skip_modules: true).name
34
+ pattern_id.cardname
35
35
  end
36
36
 
37
37
  def pattern_applies? card
@@ -44,7 +44,7 @@ class Card
44
44
 
45
45
  def module_key anchor_codes
46
46
  return pattern_code.to_s.camelize if anchorless?
47
- return unless anchor_codes # is this not an error?
47
+ return unless anchor_codes # not all anchors have codenames
48
48
 
49
49
  ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
50
50
  end
@@ -1,54 +1,65 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ # Each deck can have countless sets of cards, each of which follows one of a small
4
+ # list of patterns. This module provides methods for managing those patterns.
5
+ module Pattern
4
6
  class << self
7
+ # Pattern classes all the patterns except for Abstract.
8
+ # They are concrete because they are defined on a set of cards
9
+ # (while abstract sets must be included on them explicitly).
10
+ #
11
+ # @return [Array <Class>]
5
12
  def concrete
6
13
  @concrete ||= []
7
14
  end
8
15
 
16
+ # Pattern classes that can be reloaded without reloading Card
17
+ # (everything but all)
18
+ # @return [Array <Class>]
19
+ def reloadables
20
+ concrete - [Set::All] + Abstract
21
+ end
22
+
23
+ # remove reloadable sets and prepare for reloading
9
24
  def reset
10
25
  reloadables.each do |set_pattern|
11
26
  Set.const_remove_if_defined set_pattern.to_s.split("::").last
12
27
  end
13
- @concrete = []
14
- @card_keys = @codes = @nonbase_codes = @ids = nil
15
- end
16
-
17
- def reloadables
18
- r = concrete.push(Abstract)
19
- r.delete Set::All
20
- r
28
+ @concrete = @codes = @type_assigner_codes = @nonbase_codes = @ids = nil
21
29
  end
22
30
 
31
+ # finds pattern class associated with codename
32
+ # e.g. find(:type) returns `Card::Set::Type`
33
+ #
34
+ # @return [Class] pattern class
23
35
  def find pattern_code
24
36
  concrete.find { |sub| sub.pattern_code == pattern_code }
25
37
  end
26
38
 
27
- def card_keys
28
- @card_keys ||=
29
- concrete.each_with_object({}) do |set_pattern, hash|
30
- hash[set_pattern.pattern_id.cardname.key] = true
31
- end
39
+ # list of codenames of pattern cards
40
+ # @return [Array <Symbol>]
41
+ def codes
42
+ @codes ||= concrete.map(&:pattern_code).to_set
32
43
  end
33
44
 
45
+ # list of lists of codenames in pattern load order
46
+ # @return [Array <Array <Symbol>>]
34
47
  def grouped_codes with_all: true
35
48
  g = [[:abstract], nonbase_codes.reverse]
36
49
  g.unshift [:all] if with_all
37
50
  g
38
51
  end
39
52
 
53
+ # list of ids of pattern cards
54
+ # @return [Array <Integer>]
40
55
  def ids
41
56
  @ids ||= concrete.map(&:pattern_id)
42
57
  end
43
58
 
44
59
  private
45
60
 
46
- def codes
47
- @codes ||= concrete.map(&:pattern_code)
48
- end
49
-
50
61
  def nonbase_codes
51
- @nonbase_codes ||= codes.tap { |list| list.delete :all }
62
+ @nonbase_codes ||= codes.to_a - [:all]
52
63
  end
53
64
  end
54
65
  end
@@ -1,6 +1,6 @@
1
1
  class Card
2
2
  module Set
3
- # ActiveCard support: accessing plus cards as attributes
3
+ # accessing plus cards as attributes
4
4
  module Trait
5
5
  def card_accessor *args
6
6
  options = args.extract_options!
@@ -45,11 +45,25 @@ class Card
45
45
  define_trait_card trait, new_opts
46
46
  define_trait_reader trait if options[:reader]
47
47
  define_trait_writer trait if options[:writer]
48
+ assign_trait_type trait, options[:type]
48
49
 
49
50
  mod_traits[trait.to_sym] = options
50
51
  end
51
52
  end
52
53
 
54
+ def assign_trait_type trait, type
55
+ return unless type && (parts = trait_module_key_parts trait)
56
+ assign_type type, normalize_const(parts)
57
+ end
58
+
59
+ def trait_module_key_parts trait
60
+ if all_set?
61
+ [:right, trait]
62
+ elsif type_set?
63
+ [:type_plus_right, set_name_parts.last, trait]
64
+ end
65
+ end
66
+
53
67
  def new_trait_opts options
54
68
  %i[type default_content].each_with_object({}).each do |key, hash|
55
69
  hash[key] = options[key] if options[key]
@@ -58,6 +72,7 @@ class Card
58
72
 
59
73
  def define_trait_card trait, opts
60
74
  define_method "#{trait}_card" do
75
+ # opts = opts.clone.merge supercard: card
61
76
  fetch trait.to_sym, new: opts.clone, eager_cache: true
62
77
  end
63
78
  end
data/lib/card/set/type.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  class Card
2
2
  module Set
3
3
  class Type < Pattern::Base
4
+ cattr_accessor :assignment
5
+ self.assignment = {}
6
+
4
7
  def initialize card
5
8
  super
6
9
  # support type inheritance
@@ -53,9 +53,7 @@ class Card
53
53
 
54
54
  def new_by_card card
55
55
  card.supercard = @context_card
56
- if !card.name.simple? && card.name.field_of?(@context_card.name)
57
- card.superleft = @context_card
58
- end
56
+ card.update_superleft card.name
59
57
  @keys << card.key
60
58
  Card.write_to_soft_cache card
61
59
  card.director = @context_card.director.subdirectors.add card
@@ -2,18 +2,6 @@ class Card
2
2
  class Subcards
3
3
  # subcard-related Card instance methods
4
4
  module All
5
- def subcard card_name
6
- subcards.card card_name
7
- end
8
-
9
- def subfield field_name
10
- subcards.field field_name
11
- end
12
-
13
- def field? tag
14
- field(tag) || subfield(tag)
15
- end
16
-
17
5
  def subcards
18
6
  @subcards ||= Card::Subcards.new self
19
7
  end
@@ -22,66 +10,50 @@ class Card
22
10
  subcards.present?
23
11
  end
24
12
 
25
- def expire_subcards
26
- subcards.clear
27
- end
28
-
29
- # phase_method :attach_subcard, before: :store do |name_or_card, args=nil|
30
- # TODO: handle differently in different stages
31
- def add_subcard name_or_card, args={}
32
- subcards.add name_or_card, args
33
- end
34
- alias_method :attach_subcard, :add_subcard
35
-
36
- def add_subcard! name_or_card, args={}
37
- subcard = subcards.add name_or_card, args
38
- subcard.director.reset_stage
39
- subcard
13
+ def subcard card_name, args={}
14
+ if (sc = subcards.card card_name)
15
+ sc.assign_attributes args
16
+ sc
17
+ else
18
+ subcards.add card_name, args
19
+ end
40
20
  end
41
- alias_method :attach_subcard!, :add_subcard!
42
21
 
43
- # phase_method :attach_subfield, before: :approve do |name_or_card, args=nil|
44
- def attach_subfield name_or_card, args={}
45
- subcards.add_field name_or_card, args
22
+ def subcard_content card_name
23
+ subcards.card(card_name)&.content
46
24
  end
47
- alias_method :add_subfield, :attach_subfield
48
25
 
49
- def attach_subfield! name_or_card, args={}
50
- subcard = subcards.add_field name_or_card, args
51
- subcard.director.reset_stage
52
- subcard
26
+ def subcard? card_name
27
+ subcards.card(card_name).present?
53
28
  end
54
29
 
55
- def detach_subcard name_or_card
56
- subcards.remove name_or_card
30
+ def subfield field_name, args={}
31
+ if (sf = subcards.field field_name)
32
+ sf.assign_attributes args
33
+ sf
34
+ else
35
+ subcards.add_field field_name, args
36
+ end
57
37
  end
58
- alias_method :remove_subcard, :detach_subcard
59
38
 
60
- def detach_subfield name_or_card
61
- subcards.remove_field name_or_card
39
+ def subfield_content field_name
40
+ subcards.field(field_name)&.content
62
41
  end
63
- alias_method :remove_subfield, :detach_subfield
64
42
 
65
- def clear_subcards
66
- subcards.clear
43
+ def subfield? field_name
44
+ subcards.field(field_name).present?
67
45
  end
68
46
 
69
- # ensures subfield is present
70
- # does NOT override subfield content if already present
71
- def ensure_subfield field_name, args={}
72
- if subfield_present? field_name
73
- subfield field_name
74
- else
75
- add_subfield field_name, args
76
- end
47
+ def field? tag
48
+ field(tag) || subfield?(tag)
77
49
  end
78
50
 
79
- def subfield_present? field_name
80
- subfield(field_name)&.content&.present?
51
+ def drop_subcard name_or_card
52
+ subcards.remove name_or_card
81
53
  end
82
54
 
83
- def deep_clear_subcards
84
- subcards.deep_clear
55
+ def drop_subfield name_or_card
56
+ subcards.remove_field name_or_card
85
57
  end
86
58
 
87
59
  def handle_subcard_errors
@@ -93,6 +65,8 @@ class Card
93
65
  end
94
66
  end
95
67
 
68
+ private
69
+
96
70
  def subcard_error subcard, error
97
71
  msg = error.message
98
72
  msg = "#{error.attribute} #{msg}" unless %i[content abort].member? error.attribute