card 1.103.3 → 1.104.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/environments/development.rb +4 -2
- data/config/environments/test.rb +1 -1
- data/config/initializers/01_core_extensions/array.rb +4 -1
- data/config/initializers/01_core_extensions/object.rb +1 -1
- data/config/initializers/02_patches/active_record.rb +16 -17
- data/config/locales/de.yml +8 -564
- data/config/locales/es.yml +2 -3
- data/db/migrate/20110511221913_require_earlier_migrations.rb +1 -1
- data/db/migrate/20120105203350_require_1_8_migrations.rb +1 -1
- data/db/migrate/20121111025347_require_1_10_migrations.rb +1 -1
- data/db/migrate/20211128040849_virtuals_updated_at.rb +11 -0
- data/db/migrate_core_cards/20140307231621_user_data_to_cards.rb +0 -1
- data/db/migrate_core_cards/20190502130029_add_shark_and_help_desk_role.rb +0 -1
- data/db/schema.rb +19 -16
- data/db/seed/new/card_actions.yml +1323 -2091
- data/db/seed/new/card_acts.yml +2 -2
- data/db/seed/new/card_references.yml +629 -741
- data/db/seed/new/cards.yml +2593 -5557
- data/db/seed/new/schema_migrations.yml +2 -0
- data/db/seed/new/schema_migrations_core_cards.yml +8 -0
- data/db/seed/test/fixtures/card_actions.yml +4304 -5144
- data/db/seed/test/fixtures/card_acts.yml +780 -840
- data/db/seed/test/fixtures/card_changes.yml +110 -110
- data/db/seed/test/fixtures/card_references.yml +2908 -2992
- data/db/seed/test/fixtures/cards.yml +8781 -11961
- data/db/seed/test/fixtures/schema_migrations.yml +2 -0
- data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
- data/db/test_seed.rb +2 -5
- data/db/version.txt +1 -1
- data/db/version_core_cards.txt +1 -1
- data/lib/card/auth/current.rb +1 -1
- data/lib/card/auth/permissions.rb +37 -35
- data/lib/card/content/all.rb +3 -3
- data/lib/card/content/chunk.rb +1 -0
- data/lib/card/director/act_direction.rb +1 -3
- data/lib/card/director/card_methods.rb +0 -1
- data/lib/card/director/phases.rb +1 -0
- data/lib/card/director.rb +1 -0
- data/lib/card/env/location.rb +8 -8
- data/lib/card/env/serializable.rb +33 -0
- data/lib/card/env/serialization.rb +14 -6
- data/lib/card/env/slot_options.rb +1 -1
- data/lib/card/env/support.rb +30 -0
- data/lib/card/env.rb +13 -68
- data/lib/card/fetch/all.rb +3 -3
- data/lib/card/fetch/card_class.rb +5 -11
- data/lib/card/fetch/results.rb +2 -2
- data/lib/card/format/error.rb +2 -2
- data/lib/card/format.rb +1 -1
- data/lib/card/model/save_helper/save_arguments.rb +2 -2
- data/lib/card/model/save_helper.rb +2 -2
- data/lib/card/name/all/descendants.rb +9 -7
- data/lib/card/name/all/parts.rb +1 -1
- data/lib/card/name/all.rb +4 -3
- data/lib/card/name/card_class.rb +1 -0
- data/lib/card/name/fields_and_traits.rb +6 -30
- data/lib/card/name/name_variants.rb +5 -1
- data/lib/card/name.rb +0 -8
- data/lib/card/query/abstract_query/tie.rb +2 -3
- data/lib/card/query/card_query/normalization.rb +1 -1
- data/lib/card/query/sql_statement/order.rb +5 -6
- data/lib/card/query/value.rb +10 -7
- data/lib/card/reference/all.rb +9 -7
- data/lib/card/reference.rb +36 -41
- data/lib/card/rule/all.rb +3 -3
- data/lib/card/set/advanced_api.rb +5 -0
- data/lib/card/set/event/delayed_event.rb +8 -1
- data/lib/card/set/event.rb +1 -0
- data/lib/card/set/helpers.rb +30 -17
- data/lib/card/set/pattern/all.rb +13 -4
- data/lib/card/set/pattern/base.rb +12 -18
- data/lib/card/set/pattern/class_methods.rb +13 -13
- data/lib/card/set/pattern.rb +30 -19
- data/lib/card/set/trait.rb +16 -1
- data/lib/card/set/type.rb +3 -0
- data/lib/card/subcards/add.rb +1 -3
- data/lib/card/subcards/all.rb +30 -56
- data/lib/card/view/options.rb +7 -5
- data/lib/card/view/permission.rb +4 -11
- data/lib/cardio/cli.rb +1 -0
- data/lib/cardio/commands/custom.rb +60 -0
- data/lib/cardio/commands/rake_command/parser.rb +49 -48
- data/lib/cardio/commands/rake_command.rb +17 -15
- data/lib/cardio/commands/rspec_command.rb +2 -0
- data/lib/cardio/commands.rb +69 -69
- data/lib/cardio/generators.rb +56 -3
- data/lib/cardio/migration/deck.rb +0 -0
- data/lib/cardio/migration/deck_structure.rb +2 -0
- data/lib/cardio/migration/import/import_data/card_content.rb +1 -1
- data/lib/cardio/migration/import.rb +2 -2
- data/lib/cardio/migration.rb +26 -2
- data/lib/cardio/mod/class_methods.rb +112 -0
- data/lib/cardio/mod/dirs.rb +15 -11
- data/lib/cardio/mod/eat/edibles.rb +92 -0
- data/lib/cardio/mod/eat.rb +81 -0
- data/lib/cardio/mod/load_strategy/tmp_files.rb +1 -1
- data/lib/cardio/mod/modfile_api.rb +5 -0
- data/lib/cardio/mod/poop.rb +135 -0
- data/lib/cardio/mod.rb +20 -80
- data/lib/cardio/railtie.rb +20 -8
- data/lib/cardio/schema.rb +11 -10
- data/lib/cardio/version.rb +35 -0
- data/lib/cardio.rb +12 -0
- data/lib/generators/deck/deck_generator.rb +3 -2
- data/lib/generators/deck/templates/Gemfile.erb +0 -4
- data/lib/generators/deck/templates/config/application.rb.erb +74 -55
- data/lib/generators/deck/templates/rspec.erb +1 -1
- data/lib/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -1
- data/lib/generators/mod/USAGE +1 -0
- data/lib/tasks/card/migrate.rake +41 -1
- data/lib/tasks/card/mod.rake +15 -8
- data/lib/tasks/card.rake +47 -87
- data/mod/admin/locales/de.yml +4 -0
- data/mod/admin/set/self/admin.rb +10 -8
- data/mod/core/data/production.yml +7 -0
- data/mod/core/data/test.yml +30 -0
- data/mod/core/locales/de.yml +28 -0
- data/mod/core/set/all/assign_attributes.rb +1 -33
- data/mod/core/set/all/content.rb +3 -1
- data/mod/core/set/all/initialize.rb +1 -4
- data/mod/core/set/all/name_events.rb +3 -18
- data/mod/core/set/all/reference_events.rb +29 -28
- data/mod/core/set/all/subcards.rb +6 -2
- data/mod/core/set/all/trash.rb +2 -3
- data/mod/core/set/all/type.rb +67 -18
- data/mod/core/set/self/version.rb +1 -1
- data/mod/core/spec/set/self/trash_spec.rb +1 -1
- data/mod/standard/{file → data/files}/favicon/image-icon.png +0 -0
- data/mod/standard/{file → data/files}/favicon/image-large.png +0 -0
- data/mod/standard/{file → data/files}/favicon/image-medium.png +0 -0
- data/mod/standard/{file → data/files}/favicon/image-original.png +0 -0
- data/mod/standard/{file → data/files}/favicon/image-small.png +0 -0
- data/mod/standard/{file → data/files}/logo/image-original.svg +0 -0
- metadata +39 -29
- data/db/migrate_core_cards/20150605115802_add_performance_log_card.rb +0 -7
- data/lib/card/env/request_assignments.rb +0 -24
- data/lib/card/set/code_nest.rb +0 -15
- data/lib/card/version.rb +0 -11
- data/lib/cardio/commands/USAGE +0 -28
- data/lib/cardio/generators/class_methods.rb +0 -35
- data/lib/tasks/card/asset.rake +0 -22
- data/mod/core/spec/set/all/clean_me_spec.rb +0 -258
- data/mod/core/spec/set/all/export_spec.rb +0 -71
- data/tmpsets/set_pattern/100-all.rb +0 -22
- data/tmpsets/set_pattern/101-all_plus.rb +0 -24
- data/tmpsets/set_pattern/102-type.rb +0 -40
- data/tmpsets/set_pattern/103-star.rb +0 -26
- data/tmpsets/set_pattern/104-rstar.rb +0 -28
- data/tmpsets/set_pattern/105-rule.rb +0 -28
- data/tmpsets/set_pattern/106-right.rb +0 -35
- data/tmpsets/set_pattern/107-type_plus_right.rb +0 -43
- data/tmpsets/set_pattern/108-self.rb +0 -34
data/lib/card/name/card_class.rb
CHANGED
@@ -12,14 +12,9 @@ class Card
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Card::Name]
|
15
|
-
def field_name
|
16
|
-
|
17
|
-
|
18
|
-
trait_name tag_name
|
19
|
-
else
|
20
|
-
tag_name = tag_name.to_s[1..-1] if tag_name.to_s[0] == "+"
|
21
|
-
[self, tag_name].to_name
|
22
|
-
end
|
15
|
+
def field_name tag
|
16
|
+
tag = tag.to_s[1..-1] if !tag.is_a?(Symbol) && tag.to_s[0] == "+"
|
17
|
+
[self, tag].to_name
|
23
18
|
end
|
24
19
|
|
25
20
|
# @return [True/False]
|
@@ -29,10 +24,12 @@ class Card
|
|
29
24
|
if context.present?
|
30
25
|
absolute_name(context).left_name.key == context.to_name.key
|
31
26
|
else
|
32
|
-
s.match(/^\s*\+[^+]+$/)
|
27
|
+
s.match?(/^\s*\+[^+]+$/)
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
31
|
+
# name is relative name containing only the rightmost part
|
32
|
+
# @return [True/False]
|
36
33
|
def field_only?
|
37
34
|
relative? && stripped.to_name.parts.reject(&:blank?).first == parts.last
|
38
35
|
end
|
@@ -40,27 +37,6 @@ class Card
|
|
40
37
|
def relative_field_name tag_name
|
41
38
|
field_name(tag_name).name_from self
|
42
39
|
end
|
43
|
-
|
44
|
-
# @return [String]
|
45
|
-
def trait tag_code
|
46
|
-
name = trait_name tag_code
|
47
|
-
name.s
|
48
|
-
end
|
49
|
-
|
50
|
-
# @return [Card::Name]
|
51
|
-
def trait_name tag_code
|
52
|
-
Card::Name[self, tag_code.to_sym]
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [True/False]
|
56
|
-
def trait_name? *traitlist
|
57
|
-
return false unless compound?
|
58
|
-
|
59
|
-
right_key = right_name.key
|
60
|
-
traitlist.any? do |codename|
|
61
|
-
Card::Codename.name(codename)&.key == right_key
|
62
|
-
end
|
63
|
-
end
|
64
40
|
end
|
65
41
|
end
|
66
42
|
end
|
@@ -23,13 +23,17 @@ class Card
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def card_id
|
26
|
-
|
26
|
+
Lexicon.id self
|
27
27
|
end
|
28
28
|
|
29
29
|
# @return [Symbol] codename of card with name
|
30
30
|
def codename
|
31
31
|
Codename[card_id]
|
32
32
|
end
|
33
|
+
|
34
|
+
def codename_or_string
|
35
|
+
codename || s
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
data/lib/card/name.rb
CHANGED
@@ -93,9 +93,8 @@ class Card
|
|
93
93
|
|
94
94
|
def id_from_val val
|
95
95
|
case val
|
96
|
-
when Integer
|
97
|
-
when String then
|
98
|
-
when Symbol then Card::Codename.id(val) || -999
|
96
|
+
when Integer then val
|
97
|
+
when String, Symbol then val.card_id || -999
|
99
98
|
end
|
100
99
|
end
|
101
100
|
end
|
@@ -28,7 +28,7 @@ class Card
|
|
28
28
|
|
29
29
|
def normalize_value val
|
30
30
|
case val
|
31
|
-
when Integer, Float, Hash, Symbol, NilClass then val
|
31
|
+
when Integer, Float, Hash, Symbol, NilClass, ActiveRecord::Relation then val
|
32
32
|
when String then normalize_string_value val
|
33
33
|
when Array then normalize_array_value val
|
34
34
|
else raise Error::BadQuery, "Invalid value type: #{val.class} (#{val.inspect})"
|
@@ -18,12 +18,15 @@ class Card
|
|
18
18
|
module Order
|
19
19
|
def order
|
20
20
|
full_syntax do
|
21
|
-
|
21
|
+
dirs = order_directives
|
22
|
+
"ORDER BY #{dirs.join ', '}" if dirs.present?
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def order_directives
|
26
|
-
|
27
|
+
return if @mods[:sort].blank?
|
28
|
+
|
29
|
+
Array.wrap(@mods[:sort]).map do |order_key|
|
27
30
|
order_directive order_key
|
28
31
|
end
|
29
32
|
end
|
@@ -58,10 +61,6 @@ class Card
|
|
58
61
|
safe_sql @mods[:dir]
|
59
62
|
end
|
60
63
|
end
|
61
|
-
|
62
|
-
def order_config
|
63
|
-
@mods[:sort].blank? ? "update" : @mods[:sort]
|
64
|
-
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
data/lib/card/query/value.rb
CHANGED
@@ -32,9 +32,10 @@ class Card
|
|
32
32
|
|
33
33
|
def parse_value value
|
34
34
|
case value
|
35
|
-
when Array
|
36
|
-
when
|
37
|
-
|
35
|
+
when Array then parse_array_value value.clone
|
36
|
+
when ActiveRecord::Relation then ["in", value]
|
37
|
+
when nil then ["is", nil]
|
38
|
+
else ["=", parse_simple_value(value)]
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -48,7 +49,8 @@ class Card
|
|
48
49
|
when String, Integer then value
|
49
50
|
when Symbol then value.to_s
|
50
51
|
when nil then nil
|
51
|
-
else
|
52
|
+
else
|
53
|
+
raise Error::BadQuery, "Invalid property value: #{value.inspect}"
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
@@ -66,9 +68,10 @@ class Card
|
|
66
68
|
|
67
69
|
def sqlize v
|
68
70
|
case v
|
69
|
-
when Query
|
70
|
-
when
|
71
|
-
when
|
71
|
+
when Query then v.to_sql
|
72
|
+
when ActiveRecord::Relation then "(#{v.to_sql})"
|
73
|
+
when Array then sqlize_array v
|
74
|
+
when nil then "NULL"
|
72
75
|
else quote(v.to_s)
|
73
76
|
end
|
74
77
|
end
|
data/lib/card/reference/all.rb
CHANGED
@@ -21,7 +21,7 @@ class Card
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def referer_cards_from_references references
|
24
|
-
references.map(&:referer_id).uniq.map(
|
24
|
+
references.map(&:referer_id).uniq.map(&:card).compact
|
25
25
|
end
|
26
26
|
|
27
27
|
# cards that self refers to
|
@@ -62,11 +62,13 @@ class Card
|
|
62
62
|
Reference.mass_insert reference_values_array(ref_hash)
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
# replace references in card content
|
66
|
+
def swap_names old_name, new_name
|
67
|
+
cont = content_object
|
68
|
+
cont.find_chunks(:Reference).each do |chunk|
|
69
|
+
chunk.swap_name old_name, new_name
|
70
|
+
end
|
71
|
+
cont.to_s
|
70
72
|
end
|
71
73
|
|
72
74
|
private
|
@@ -122,7 +124,7 @@ class Card
|
|
122
124
|
end
|
123
125
|
|
124
126
|
# Partial references are needed to track references to virtual cards.
|
125
|
-
# For example a link to
|
127
|
+
# For example a link to virtual card [[A+*self]] won't have a referee_id,
|
126
128
|
# but when A's name is changed we have to find and update that link.
|
127
129
|
def interpret_partial_references ref_hash, referee_name
|
128
130
|
return if referee_name.simple?
|
data/lib/card/reference.rb
CHANGED
@@ -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
|
-
|
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
|
-
#
|
31
|
-
def
|
32
|
-
|
33
|
-
|
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
|
-
|
56
|
-
|
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.
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
68
|
-
rule_id = lookup_hash["#{
|
69
|
-
rule_id ||= fallback_suffix && lookup_hash["#{
|
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
|
data/lib/card/set/event.rb
CHANGED
data/lib/card/set/helpers.rb
CHANGED
@@ -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
|
data/lib/card/set/pattern/all.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Card
|
2
2
|
module Set
|
3
|
-
|
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 = @
|
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
|
55
|
-
@
|
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
|
-
|
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
|
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) ||
|
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
|
-
|
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 =
|
74
|
-
|
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
|
78
|
-
if
|
79
|
-
|
71
|
+
def rule_lookup_key
|
72
|
+
if anchorless?
|
73
|
+
pattern_code.to_s
|
80
74
|
elsif @anchor_id
|
81
|
-
"#{@anchor_id}+#{
|
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
|
-
|
3
|
+
module Pattern
|
4
4
|
# methods for Set::Pattern classes
|
5
5
|
module ClassMethods
|
6
|
-
attr_accessor :pattern_code, :
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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 #
|
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
|