card 1.103.2 → 1.104.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/environments/development.rb +4 -2
  4. data/config/environments/production.rb +9 -9
  5. data/config/environments/test.rb +1 -1
  6. data/config/initializers/01_core_extensions/array.rb +4 -1
  7. data/config/initializers/01_core_extensions/object.rb +1 -1
  8. data/config/initializers/02_patches/active_record.rb +16 -17
  9. data/config/locales/de.yml +8 -564
  10. data/config/locales/es.yml +2 -3
  11. data/db/migrate/20110511221913_require_earlier_migrations.rb +1 -1
  12. data/db/migrate/20120105203350_require_1_8_migrations.rb +1 -1
  13. data/db/migrate/20121111025347_require_1_10_migrations.rb +1 -1
  14. data/db/migrate/20211128040849_virtuals_updated_at.rb +11 -0
  15. data/db/migrate_core_cards/20130411191151_renaming_for_menu.rb +0 -1
  16. data/db/migrate_core_cards/20140317035504_account_requests_to_signups.rb +0 -2
  17. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +0 -2
  18. data/db/migrate_core_cards/20190417142612_reorganize_scripts_2.rb +1 -3
  19. data/db/migrate_core_cards/20190502130029_add_shark_and_help_desk_role.rb +1 -2
  20. data/db/migrate_core_cards/20190710090209_homepage_tweaks.rb +3 -7
  21. data/db/migrate_core_cards/20190823220018_cleanup_for_decko_1_0.rb +2 -4
  22. data/db/migrate_core_cards/20190902193208_input_type.rb +3 -8
  23. data/db/migrate_core_cards/20190904174403_token_upgrade.rb +1 -1
  24. data/db/migrate_core_cards/data/1.12_stylesheets/traditional.scss +1 -2
  25. data/db/schema.rb +19 -16
  26. data/db/seed/new/card_actions.yml +2615 -3383
  27. data/db/seed/new/card_acts.yml +3 -3
  28. data/db/seed/new/card_references.yml +1588 -1707
  29. data/db/seed/new/cards.yml +5450 -8416
  30. data/db/seed/new/schema_migrations.yml +2 -0
  31. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  32. data/db/seed/test/fixtures/card_actions.yml +4304 -5144
  33. data/db/seed/test/fixtures/card_acts.yml +780 -840
  34. data/db/seed/test/fixtures/card_changes.yml +110 -110
  35. data/db/seed/test/fixtures/card_references.yml +2908 -2992
  36. data/db/seed/test/fixtures/cards.yml +8775 -11955
  37. data/db/seed/test/fixtures/schema_migrations.yml +2 -0
  38. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  39. data/db/test_seed.rb +2 -5
  40. data/db/version.txt +1 -1
  41. data/db/version_core_cards.txt +1 -1
  42. data/lib/card/auth/current.rb +1 -1
  43. data/lib/card/auth/permissions.rb +37 -35
  44. data/lib/card/content/all.rb +3 -3
  45. data/lib/card/content/chunk.rb +1 -1
  46. data/lib/card/content/diff/summary.rb +14 -18
  47. data/lib/card/content.rb +9 -1
  48. data/lib/card/director/act_direction.rb +6 -6
  49. data/lib/card/director/card_methods.rb +0 -1
  50. data/lib/card/director/phases.rb +1 -0
  51. data/lib/card/director/stages.rb +2 -0
  52. data/lib/card/director.rb +1 -0
  53. data/lib/card/fetch/all.rb +3 -3
  54. data/lib/card/fetch/card_class.rb +5 -11
  55. data/lib/card/fetch/results.rb +8 -8
  56. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/migration_file.rb +0 -0
  57. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/ruby_file.rb +0 -0
  58. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/source_file.rb +0 -0
  59. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card.rb +0 -5
  60. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/haml_card.rb +0 -0
  61. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/output_helper.rb +0 -0
  62. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/script_card.rb +0 -0
  63. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/style_card.rb +0 -0
  64. data/lib/card/{tasks/card/file_card_creator.rb → file_card_creator.rb} +0 -5
  65. data/lib/card/format/content.rb +5 -7
  66. data/lib/card/format/error.rb +2 -2
  67. data/lib/card/format/render.rb +10 -10
  68. data/lib/card/format.rb +3 -8
  69. data/lib/card/lexicon.rb +30 -7
  70. data/lib/card/model/save_helper/save_arguments.rb +2 -2
  71. data/lib/card/model/save_helper.rb +3 -3
  72. data/lib/card/name/all/descendants.rb +9 -7
  73. data/lib/card/name/all/parts.rb +1 -1
  74. data/lib/card/name/all.rb +4 -3
  75. data/lib/card/name/card_class.rb +2 -1
  76. data/lib/card/name/fields_and_traits.rb +6 -30
  77. data/lib/card/name/name_variants.rb +5 -1
  78. data/lib/card/name.rb +6 -14
  79. data/lib/card/query/abstract_query/tie.rb +2 -3
  80. data/lib/card/query/card_query/normalization.rb +1 -1
  81. data/lib/card/query/sql_statement/order.rb +5 -6
  82. data/lib/card/query/value.rb +10 -7
  83. data/lib/card/reference/all.rb +9 -7
  84. data/lib/card/reference.rb +36 -41
  85. data/lib/card/rule/all.rb +3 -3
  86. data/lib/card/set/advanced_api.rb +5 -0
  87. data/lib/card/set/card_methods.rb +13 -0
  88. data/lib/card/set/event/delayed_event.rb +8 -1
  89. data/lib/card/set/event/skip_and_trigger.rb +8 -0
  90. data/lib/card/set/event.rb +1 -0
  91. data/lib/card/set/format/abstract_format/wrapper.rb +1 -1
  92. data/lib/card/set/format/abstract_format.rb +2 -1
  93. data/lib/card/set/format.rb +2 -3
  94. data/lib/card/set/helpers.rb +68 -0
  95. data/lib/card/set/inheritance.rb +1 -1
  96. data/lib/card/set/pattern/all.rb +20 -10
  97. data/lib/card/set/pattern/base.rb +12 -18
  98. data/lib/card/set/pattern/class_methods.rb +13 -13
  99. data/lib/card/set/pattern.rb +46 -24
  100. data/lib/card/set/registrar.rb +8 -2
  101. data/lib/card/set/trait.rb +16 -1
  102. data/lib/card/set/type.rb +3 -0
  103. data/lib/card/set.rb +14 -7
  104. data/lib/card/subcards/add.rb +1 -3
  105. data/lib/card/subcards/all.rb +30 -56
  106. data/lib/card/view/classy.rb +15 -27
  107. data/lib/card/view/options/voo_api.rb +3 -1
  108. data/lib/card/view/options.rb +7 -5
  109. data/lib/card/view/permission.rb +4 -11
  110. data/lib/card/view.rb +1 -0
  111. data/lib/card.rb +9 -11
  112. data/lib/cardio/cli.rb +1 -0
  113. data/lib/cardio/commands/custom.rb +60 -0
  114. data/lib/cardio/commands/rake_command/parser.rb +49 -48
  115. data/lib/cardio/commands/rake_command.rb +17 -15
  116. data/lib/cardio/commands/rspec_command.rb +2 -0
  117. data/lib/cardio/commands.rb +69 -69
  118. data/lib/cardio/generators/deck_helper.rb +0 -4
  119. data/lib/cardio/generators.rb +56 -3
  120. data/lib/cardio/migration/deck.rb +0 -0
  121. data/lib/cardio/migration/deck_structure.rb +2 -0
  122. data/lib/cardio/migration/import/import_data/card_content.rb +1 -1
  123. data/lib/cardio/migration/import.rb +2 -2
  124. data/lib/cardio/migration.rb +26 -2
  125. data/lib/cardio/mod/class_methods.rb +112 -0
  126. data/lib/cardio/mod/dirs.rb +15 -11
  127. data/lib/cardio/mod/eat/edibles.rb +92 -0
  128. data/lib/cardio/mod/eat.rb +81 -0
  129. data/lib/cardio/mod/load_strategy/set_tmp_files.rb +10 -4
  130. data/lib/cardio/mod/load_strategy/tmp_files.rb +1 -1
  131. data/lib/cardio/mod/load_strategy.rb +3 -4
  132. data/lib/cardio/mod/loader/set_loader.rb +13 -13
  133. data/lib/cardio/mod/loader.rb +1 -1
  134. data/lib/cardio/mod/modfile_api.rb +5 -0
  135. data/lib/cardio/mod/poop.rb +135 -0
  136. data/lib/cardio/mod.rb +20 -80
  137. data/lib/cardio/railtie.rb +24 -6
  138. data/lib/cardio/schema.rb +11 -10
  139. data/lib/cardio/version.rb +35 -0
  140. data/lib/cardio.rb +4 -0
  141. data/lib/generators/deck/deck_generator.rb +3 -2
  142. data/lib/generators/deck/templates/Gemfile.erb +1 -5
  143. data/lib/generators/deck/templates/Rakefile.erb +6 -2
  144. data/lib/generators/deck/templates/rspec.erb +1 -1
  145. data/lib/generators/deck/templates/simplecov.rb.erb +7 -11
  146. data/lib/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -1
  147. data/lib/generators/mod/USAGE +1 -0
  148. data/lib/{card/tasks → tasks}/card/create.rake +0 -0
  149. data/lib/{card/tasks → tasks}/card/migrate.rake +41 -1
  150. data/lib/{card/tasks → tasks}/card/mod.rake +15 -8
  151. data/lib/tasks/card.rake +65 -0
  152. data/mod/admin/locales/de.yml +4 -0
  153. data/mod/admin/set/all/admin.rb +16 -0
  154. data/mod/admin/set/self/admin.rb +12 -14
  155. data/mod/admin/set/self/admin_info.rb +2 -5
  156. data/mod/core/data/production.yml +7 -0
  157. data/mod/core/data/test.yml +30 -0
  158. data/mod/core/locales/de.yml +28 -0
  159. data/mod/core/locales/en.yml +4 -5
  160. data/mod/core/set/all/assign_attributes.rb +1 -33
  161. data/mod/core/set/all/content.rb +3 -1
  162. data/mod/core/set/all/initialize.rb +1 -4
  163. data/mod/core/set/all/name_events.rb +3 -18
  164. data/mod/core/set/all/reference_events.rb +32 -36
  165. data/mod/core/set/all/subcards.rb +6 -2
  166. data/mod/core/set/all/trash.rb +4 -6
  167. data/mod/core/set/all/type.rb +67 -18
  168. data/mod/core/set/self/version.rb +1 -1
  169. data/mod/core/spec/set/all/name_events_spec.rb +10 -10
  170. data/mod/core/spec/set/all/trash_spec.rb +1 -1
  171. data/mod/core/spec/set/self/trash_spec.rb +1 -1
  172. data/mod/standard/{file → data/files}/favicon/image-icon.png +0 -0
  173. data/mod/standard/{file → data/files}/favicon/image-large.png +0 -0
  174. data/mod/standard/{file → data/files}/favicon/image-medium.png +0 -0
  175. data/mod/standard/{file → data/files}/favicon/image-original.png +0 -0
  176. data/mod/standard/{file → data/files}/favicon/image-small.png +0 -0
  177. data/mod/standard/{file → data/files}/logo/image-original.svg +0 -0
  178. metadata +52 -42
  179. data/db/migrate_core_cards/20150605115802_add_performance_log_card.rb +0 -7
  180. data/lib/card/set/basket.rb +0 -59
  181. data/lib/card/set/code_nest.rb +0 -15
  182. data/lib/card/tasks/card/asset.rake +0 -22
  183. data/lib/card/tasks/card.rake +0 -105
  184. data/lib/card/version.rb +0 -11
  185. data/lib/cardio/commands/USAGE +0 -28
  186. data/lib/cardio/generators/class_methods.rb +0 -35
  187. data/mod/core/spec/set/all/clean_me_spec.rb +0 -258
  188. data/mod/core/spec/set/all/export_spec.rb +0 -71
  189. data/tmpsets/set_pattern/100-all.rb +0 -22
  190. data/tmpsets/set_pattern/101-all_plus.rb +0 -24
  191. data/tmpsets/set_pattern/102-type.rb +0 -40
  192. data/tmpsets/set_pattern/103-star.rb +0 -26
  193. data/tmpsets/set_pattern/104-rstar.rb +0 -28
  194. data/tmpsets/set_pattern/105-rule.rb +0 -28
  195. data/tmpsets/set_pattern/106-right.rb +0 -35
  196. data/tmpsets/set_pattern/107-type_plus_right.rb +0 -43
  197. data/tmpsets/set_pattern/108-self.rb +0 -34
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Cardio
4
4
  class Migration < ActiveRecord::Migration[4.2]
5
- include Card::Model::SaveHelper
5
+ include Card::Model::SaveHelper unless ENV["NO_CARD_LOAD"]
6
6
  @type = :deck_cards
7
7
 
8
8
  class << self
@@ -43,12 +43,36 @@ module Cardio
43
43
  Schema.assume_migrated_upto_version type
44
44
  end
45
45
 
46
+ def assume_current
47
+ migration_context do |mc|
48
+ versions = mc.migrations.map(&:version)
49
+ migrated = mc.get_all_versions
50
+ mark_as_migrated versions - migrated
51
+ end
52
+ end
53
+
46
54
  def data_path filename=nil
47
55
  File.join([migration_paths.first, "data", filename].compact)
48
56
  end
57
+
58
+ private
59
+
60
+ def mark_as_migrated versions
61
+ sql = connection.send :insert_versions_sql, versions
62
+ connection.execute sql
63
+ end
64
+
65
+ def connection
66
+ ActiveRecord::Base.connection
67
+ end
68
+
69
+ def migration_context &block
70
+ Schema.migration_context type, &block
71
+ end
49
72
  end
50
73
 
51
74
  def contentedly
75
+ return yield if ENV["NO_CARD_LOAD"]
52
76
  Card::Cache.reset_all
53
77
  Schema.mode "" do
54
78
  Card::Auth.as_bot do
@@ -111,7 +135,7 @@ module Cardio
111
135
  end
112
136
 
113
137
  # Execute this migration in the named direction
114
- # copied from ActiveRecord to wrap 'up' in 'contentendly'
138
+ # copied from ActiveRecord to wrap 'up' in 'contentedly'
115
139
  def exec_migration conn, direction
116
140
  @connection = conn
117
141
  if respond_to?(:change)
@@ -0,0 +1,112 @@
1
+ module Cardio
2
+ class Mod
3
+ # class methods for Cardio::Mod
4
+ module ClassMethods
5
+ def load
6
+ return if ENV["CARD_MODS"] == "none"
7
+
8
+ if Card.take
9
+ Loader.load_mods
10
+ else
11
+ Rails.logger.warn "empty database"
12
+ end
13
+ end
14
+
15
+ # @return an array of Rails::Path objects
16
+ def dirs
17
+ @dirs ||= Mod::Dirs.new Cardio.paths["mod"].existent
18
+ end
19
+
20
+ def fetch mod_name
21
+ dirs.fetch_mod mod_name
22
+ end
23
+
24
+ def normalize_name name
25
+ name.to_s.sub(/^card-mod-/, "")
26
+ end
27
+
28
+ def missing
29
+ Card.search(type: :mod).reject { |mod_card| fetch mod_card.modname }
30
+ end
31
+
32
+ def ensure_uninstalled
33
+ missing.each do |mod_card|
34
+ Card::Auth.as_bot do
35
+ Card[:all, :style].drop_item mod_card
36
+ delete_auto_installed_cards mod_card
37
+ end
38
+ end
39
+ end
40
+
41
+ def ensure_installed
42
+ Card::Cache.reset_all
43
+ puts "installing card mods".green
44
+ Cardio.mods.each(&:ensure)
45
+ Card::Assets.refresh_assets force: true
46
+ end
47
+
48
+ def dependencies name, nickname=true
49
+ return unless (spec = gem_spec name, nickname)
50
+
51
+ deps = spec&.dependencies || []
52
+ dep_names = deps.map { |dep| dependencies dep.name, false }
53
+ (dep_names << spec).flatten.compact.uniq
54
+ end
55
+
56
+ def each_path &block
57
+ each_simple_path(&block)
58
+ each_gem_path(&block)
59
+ end
60
+
61
+ # @return [Hash] in the form{ modname(String) => Gem::Specification }
62
+ def gem_specs
63
+ Bundler.definition.specs.each_with_object({}) do |gem_spec, h|
64
+ h[gem_spec.name] = gem_spec if gem_spec? gem_spec
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ # it would be nice if this were easier...
71
+ def delete_auto_installed_cards mod_card
72
+ auto_installed_cards(mod_card).each do |card|
73
+ card.codename = nil
74
+ card.delete!
75
+ end
76
+ end
77
+
78
+ def auto_installed_cards mod_card
79
+ [mod_card].tap do |cards|
80
+ mod_card.each_descendant do |card|
81
+ cards.unshift card
82
+ end
83
+ end
84
+ end
85
+
86
+ def gem_spec name, nickname=true
87
+ name = "card-mod-#{name}" if nickname && !name.match?(/^card-mod/)
88
+ spec = Gem::Specification.stubs_for(name)&.first
89
+ gem_spec?(spec) ? spec : nil
90
+ end
91
+
92
+ def each_simple_path &block
93
+ Cardio.paths["mod"].each do |mods_path|
94
+ Dir.glob("#{mods_path}/*").each(&block)
95
+ end
96
+ end
97
+
98
+ def each_gem_path
99
+ gem_specs.each_value do |spec|
100
+ yield spec.full_gem_path
101
+ end
102
+ end
103
+
104
+ # @return [True/False]
105
+ def gem_spec? spec
106
+ return unless spec
107
+
108
+ spec.name.match?(/^card-mod-/) || spec.metadata["card-mod"].present?
109
+ end
110
+ end
111
+ end
112
+ end
@@ -97,6 +97,13 @@ module Cardio
97
97
  fetch_mod(mod_name)&.path
98
98
  end
99
99
 
100
+ def subpaths *subdirs
101
+ @mods.each_with_object({}) do |mod, hash|
102
+ path = mod.subpath(*subdirs)
103
+ hash[mod.name] = path if path
104
+ end
105
+ end
106
+
100
107
  def fetch_mod mod_name
101
108
  @mods_by_name[Mod.normalize_name(mod_name)]
102
109
  end
@@ -129,12 +136,15 @@ module Cardio
129
136
  end
130
137
  end
131
138
 
132
- def each_public_path
133
- @mods.each do |mod|
134
- path = mod.public_path
135
- next unless Dir.exist? path
139
+ def each_subpath *subdirs
140
+ subpaths(*subdirs).each do |mod_name, subpath|
141
+ yield mod_name, subpath
142
+ end
143
+ end
136
144
 
137
- yield mod.name, path
145
+ def load_from_gemfile
146
+ Cardio::Mod.gem_specs.each do |mod_name, mod_spec|
147
+ add_gem_mod mod_name, mod_spec.full_gem_path
138
148
  end
139
149
  end
140
150
 
@@ -154,12 +164,6 @@ module Cardio
154
164
  add_mod filename unless filename.match?(/^\./)
155
165
  end
156
166
  end
157
-
158
- def load_from_gemfile
159
- Cardio::Mod.gem_specs.each do |mod_name, mod_spec|
160
- add_gem_mod mod_name, mod_spec.full_gem_path
161
- end
162
- end
163
167
  end
164
168
  end
165
169
  end
@@ -0,0 +1,92 @@
1
+ module Cardio
2
+ class Mod
3
+ class Eat
4
+ # item handling for Mod::Eat (importables)
5
+ module Edibles
6
+ # list of card attribute hashes
7
+ # @return [Array <Hash>]
8
+ def edibles
9
+ mods_with_data.map { |mod| mod_edibles mod }.flatten
10
+ end
11
+
12
+ private
13
+
14
+ # if mod is specified, consider only that mod
15
+ # @return [Array <Cardio::Mod>]
16
+ def mods_with_data
17
+ paths = Mod.dirs.subpaths "data"
18
+ mod_names = @mod ? ensure_mod_data_path(paths) : paths.keys
19
+ mod_names.map { |mod_name| Mod.fetch mod_name }
20
+ end
21
+
22
+ def ensure_mod_data_path paths
23
+ return [@mod] if paths[@mod]
24
+
25
+ raise "no data directory found for mod #{@mod}".red
26
+ end
27
+
28
+ # @return [Array <Hash>]
29
+ def mod_edibles mod
30
+ environments.map { |env| items_for_environment mod, env }.compact
31
+ end
32
+
33
+ def items_for_environment mod, env
34
+ return unless (items = items_from_yaml mod, env)
35
+
36
+ items = items.map do |item|
37
+ item.is_a?(String) ? items_from_yaml(mod, env, item) : item
38
+ end.flatten.compact
39
+ interpret_items mod, items
40
+ end
41
+
42
+ def interpret_items mod, items
43
+ each_card_hash(items) { |hash| handle_attachments mod, hash }
44
+ end
45
+
46
+ def items_from_yaml mod, env, filename=nil
47
+ source = "#{env}#{'/' if filename.present?}#{filename}.yml"
48
+ return unless (path = mod.subpath "data", source)
49
+
50
+ YAML.load_file path
51
+ end
52
+
53
+ # for processing that needs to happen on all cards, including fields
54
+ def each_card_hash items
55
+ items.each do |item|
56
+ yield item
57
+ item[:subfields]&.values&.each { |val| yield val if val.is_a? Hash }
58
+ end
59
+ items
60
+ end
61
+
62
+ def handle_attachments mod, hash
63
+ each_attachment hash do |key, filename|
64
+ hash[key] = mod_file mod, filename
65
+ hash[:mod] = mod.name if hash[:storage_type] == :coded
66
+ end
67
+ end
68
+
69
+ def each_attachment hash
70
+ attachment_keys.each { |key| yield key, hash[key] if hash.key? key }
71
+ end
72
+
73
+ def mod_file mod, filename
74
+ File.open mod.subpath("data/files", filename)
75
+ end
76
+
77
+ def attachment_keys
78
+ @attachment_keys ||= Card.uploaders.keys
79
+ end
80
+
81
+ # @return [Array <Symbol>]
82
+ # holarchical. each includes the previous
83
+ # production = [:production],
84
+ # development = [:production, :development], etc.
85
+ def environments
86
+ index = DATA_ENVIRONMENTS.index(@env&.to_sym || Rails.env.to_sym) || -1
87
+ DATA_ENVIRONMENTS[0..index]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,81 @@
1
+ require "timecop"
2
+
3
+ require "pry"
4
+
5
+ DATA_ENVIRONMENTS = %i[production development test].freeze
6
+ ENV["STORE_CODED_FILES"] = "true"
7
+
8
+ module Cardio
9
+ class Mod
10
+ # import data from data directory of mods
11
+ # (list of card attributes)
12
+ # https://docs.google.com/document/d/13K_ynFwfpHwc3t5gnLeAkZJZHco1wK063nJNYwU8qfc/edit#
13
+ class Eat
14
+ include Card::Model::SaveHelper
15
+ include Edibles
16
+
17
+ def initialize mod: nil, env: nil, user: nil, verbose: nil
18
+ @mod = mod
19
+ @env = env
20
+ @user_id = user&.card_id
21
+ @verbose = !verbose.nil?
22
+ end
23
+
24
+ def up
25
+ Card::Cache.reset_all
26
+ Card::Mailer.perform_deliveries = false
27
+ Card::Auth.as_bot do
28
+ edibles.each do |edible|
29
+ track edible do
30
+ current_user edible.delete(:user)
31
+ time_machine edible.delete(:time) do
32
+ ensure_card edible
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def track edible
42
+ rescuing edible do
43
+ # puts "eat: #{edible}" if @verbose
44
+ card = yield
45
+ puts "eaten: #{card.name}".green # if @verbose
46
+ end
47
+ end
48
+
49
+ def rescuing edible
50
+ yield
51
+ rescue StandardError => e
52
+ # binding.pry
53
+ puts edible
54
+ puts e.message.red
55
+ puts e.backtrace.join("\n") if @verbose
56
+ end
57
+
58
+ def current_user item_user
59
+ Card::Auth.current_id = item_user&.card_id || @user_id || Card::WagnBotID
60
+ end
61
+
62
+ def time_machine value, &block
63
+ return yield unless value.present?
64
+
65
+ Timecop.freeze Time.at(time_integer(value)), &block
66
+ end
67
+
68
+ def time_integer value
69
+ case value
70
+ when /^[+-]\d+$/
71
+ # plus or minus an integer (safe to eval)
72
+ eval "#{Time.now.to_i} #{value}", binding, __FILE__, __LINE__
73
+ when Integer
74
+ value
75
+ else
76
+ raise TypeError, "invalid time value: #{value}. accepts int, +int, and -int"
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -21,13 +21,19 @@ module Cardio
21
21
  end
22
22
 
23
23
  def load_tmp_files
24
- mod_dirs.each_tmp(:set) do |set_tmp_dir|
25
- Card::Set::Pattern.codes.each do |pattern|
26
- pattern_dir = "#{set_tmp_dir}/#{pattern}"
27
- Loader.load_dir "#{pattern_dir}/**" if Dir.exist? pattern_dir
24
+ pattern_groups.each do |pattern_group|
25
+ mod_dirs.each_tmp(:set) do |set_tmp_dir|
26
+ load_tmp_files_for_pattern pattern_group, set_tmp_dir
28
27
  end
29
28
  end
30
29
  end
30
+
31
+ def load_tmp_files_for_pattern pattern_group, set_tmp_dir
32
+ pattern_group.each do |pattern|
33
+ pattern_dir = "#{set_tmp_dir}/#{pattern}"
34
+ Loader.load_dir "#{pattern_dir}/**" if Dir.exist? pattern_dir
35
+ end
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -20,7 +20,7 @@ module Cardio
20
20
 
21
21
  p = Card.paths[path]
22
22
  FileUtils.rm_rf p.first, secure: true if p.existent.first
23
- Dir.mkdir p.first
23
+ FileUtils.mkdir_p p.first
24
24
  end
25
25
 
26
26
  def rewrite_tmp_files?
@@ -14,9 +14,7 @@ module Cardio
14
14
  end
15
15
 
16
16
  def class_for_set_pattern strategy
17
- return PatternTmpFiles if strategy == :tmp_files
18
-
19
- Eval
17
+ strategy == :tmp_files ? PatternTmpFiles : Eval
20
18
  end
21
19
 
22
20
  def tmp_files?
@@ -25,7 +23,8 @@ module Cardio
25
23
  end
26
24
 
27
25
  attr_reader :loader
28
- delegate :template_class, :each_file, :mod_dirs, :parts_from_path, to: :loader
26
+ delegate :template_class, :pattern_groups, :each_file, :mod_dirs, :parts_from_path,
27
+ to: :loader
29
28
 
30
29
  def initialize loader
31
30
  LoadStrategy.current = self.class
@@ -5,10 +5,6 @@ module Cardio
5
5
  # The mods are given by a Mod::Dirs object.
6
6
  # SetLoader can use three different strategies to load the set modules.
7
7
  class SetLoader < Loader
8
- def template_class
9
- SetTemplate
10
- end
11
-
12
8
  def initialize args={}
13
9
  @no_all = args.delete :no_all
14
10
  super load_strategy: args[:load_strategy], mod_dirs: args[:mod_dirs]
@@ -20,22 +16,26 @@ module Cardio
20
16
 
21
17
  def load
22
18
  super
23
- # Card::Set.process_base_modules
24
- Card::Set.clean_empty_modules
19
+ Card::Set.finalize_load
25
20
  end
26
21
 
27
- # does not include abstract
28
- def main_patterns
29
- method = @no_all ? :nonbase_codes : :codes
30
- Card::Set::Pattern.send method
22
+ def template_class
23
+ SetTemplate
31
24
  end
32
25
 
33
26
  def each_file &block
34
- # each_file_with_patterns :abstract, &block
35
- each_file_with_patterns(*main_patterns, &block)
27
+ pattern_groups.each do |pattern_group|
28
+ each_file_with_patterns pattern_group, &block
29
+ end
36
30
  end
37
31
 
38
- def each_file_with_patterns *patterns, &block
32
+ def pattern_groups
33
+ Card::Set::Pattern.grouped_codes with_all: !@no_all
34
+ end
35
+
36
+ private
37
+
38
+ def each_file_with_patterns patterns, &block
39
39
  each_mod_dir :set do |base_dir|
40
40
  patterns.each do |pattern|
41
41
  each_file_in_dir base_dir, pattern.to_s, &block
@@ -22,7 +22,7 @@ module Cardio
22
22
 
23
23
  def reload_sets
24
24
  Card::Set::Pattern.reset
25
- Card::Set.reset_modules
25
+ Card::Set.reset
26
26
  SetPatternLoader.new.load
27
27
  SetLoader.new(no_all: true).load
28
28
  end
@@ -12,6 +12,11 @@ module Cardio
12
12
  deps.each { |spec| @dirs.add_gem_mod spec.name, spec.full_gem_path }
13
13
  end
14
14
 
15
+ # load all gem mods
16
+ def gem_mods
17
+ @dirs.load_from_gemfile
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def unknown_gem_mod! name
@@ -0,0 +1,135 @@
1
+ module Cardio
2
+ class Mod
3
+ # POOP (or Plain Old OutPut) is our nickname for our standard card YAML,
4
+ # used to define cards associated with mods.
5
+ #
6
+ # Monkeys throw it around, and Sharks can eat it (if you believe this guy:
7
+ # https://www.youtube.com/watch?v=VvEa4NSqw7I).
8
+ #
9
+ # https://docs.google.com/document/d/13K_ynFwfpHwc3t5gnLeAkZJZHco1wK063nJNYwU8qfc/edit#
10
+ class Poop
11
+ def initialize **args
12
+ @mod = args[:mod]
13
+ @name = args[:name]
14
+ @cql = args[:cql]
15
+ @env = args[:env] || Rails.env
16
+ @items = args[:items]
17
+ @field_tags = args[:field_tags]
18
+ end
19
+
20
+ # @return [Array <Hash>]
21
+ def new_data
22
+ @new_data ||= cards.map { |c| c.export_hash field_tags: field_tag_marks }
23
+ end
24
+
25
+ def field_tag_marks
26
+ @field_tag_marks ||= @field_tags.to_s.split(",").map do |mark|
27
+ mark.strip.cardname.codename_or_string
28
+ end
29
+ end
30
+
31
+ # @return [String] -- MOD_DIR/data/ENVIRONMENT.yml
32
+ def filename
33
+ @filename ||= File.join mod_path, "#{@env}.yml"
34
+ end
35
+
36
+ # if output mod given,
37
+ def out
38
+ Card::Cache.reset_all
39
+ @mod ? dump : puts(new_data.to_yaml.yellow)
40
+ :success
41
+ rescue Card::Error::NotFound => e
42
+ e.message
43
+ rescue JSON::ParserError => e
44
+ e.message
45
+ end
46
+
47
+ # write yaml to file
48
+ def dump
49
+ hash = output_hash
50
+ File.write filename, hash.to_yaml
51
+ puts "#{filename} now contains #{hash.size} items".green
52
+ end
53
+
54
+ private
55
+
56
+ def cards
57
+ if @name
58
+ cards_from_name
59
+ elsif @cql
60
+ Card.search JSON.parse(@cql).reverse_merge(limit: 0)
61
+ else
62
+ raise Card::Error::NotFound, "must specify either name (-n) or CQL (-c)"
63
+ end
64
+ end
65
+
66
+ def cards_from_name
67
+ case @items
68
+ when :only
69
+ item_cards
70
+ when true
71
+ main_cards + item_cards
72
+ else
73
+ main_cards
74
+ end
75
+ end
76
+
77
+ def item_cards
78
+ main_cards.map { |mc| mc.item_cards }.flatten
79
+ end
80
+
81
+ def main_cards
82
+ @main_cards ||= @name.split(",").map { |n| require_card n }
83
+ end
84
+
85
+ def require_card name
86
+ Card.fetch(name) || raise(Card::Error::NotFound, "card not found: #{name}")
87
+ end
88
+
89
+ def output_hash
90
+ if target.present?
91
+ merge_data
92
+ target
93
+ else
94
+ new_data
95
+ end
96
+ end
97
+
98
+ def merge_data
99
+ new_data.each do |item|
100
+ if (index = target_index item)
101
+ target[index] = item
102
+ else
103
+ target << item
104
+ end
105
+ end
106
+ end
107
+
108
+ def target_index new_item
109
+ new_code = new_item[:codename]
110
+ new_name = new_item[:name].to_name
111
+ target.find_index do |t|
112
+ t.is_a?(Hash) &&
113
+ ((new_code.present? && (new_code == t[:codename])) ||
114
+ (t[:name].to_name == new_name))
115
+ end
116
+ end
117
+
118
+ def target
119
+ @target ||= old_data
120
+ end
121
+
122
+ def old_data
123
+ return nil unless File.exist? filename
124
+
125
+ YAML.safe_load File.read(filename), [Symbol]
126
+ end
127
+
128
+ # @return Path
129
+ def mod_path
130
+ Mod.dirs.subpaths("data")[@mod] ||
131
+ raise(Card::Error::NotFound, "no data directory found for mod: #{@mod}")
132
+ end
133
+ end
134
+ end
135
+ end