card 1.101.0 → 1.101.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (287) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/i18n-tasks.yml +0 -5
  4. data/config/initializers/01_core_extensions/array.rb +2 -1
  5. data/config/initializers/01_core_extensions/hash.rb +1 -0
  6. data/config/initializers/01_core_extensions/object.rb +15 -11
  7. data/config/initializers/02_patches/active_job.rb +1 -1
  8. data/config/initializers/02_patches/active_record.rb +2 -4
  9. data/config/initializers/02_patches/better_errors.rb +1 -3
  10. data/config/initializers/02_patches/kaminari.rb +2 -2
  11. data/config/initializers/deck_config.rb +1 -1
  12. data/config/initializers/inflections.rb +1 -0
  13. data/config/initializers/internationalization.rb +23 -21
  14. data/config/initializers/mime_types.rb +1 -0
  15. data/config/initializers/notification.rb +1 -0
  16. data/config/initializers/patches.rb +6 -5
  17. data/config/locales/en.yml +137 -525
  18. data/db/migrate/20110511221913_require_earlier_migrations.rb +1 -0
  19. data/db/migrate/20121111025347_require_1_10_migrations.rb +1 -0
  20. data/db/migrate/20121118114000_split_link_type.rb +1 -0
  21. data/db/migrate/20121118115000_update_link_type.rb +1 -0
  22. data/db/migrate/20130106052640_table_cleanup.rb +2 -2
  23. data/db/migrate/20130109015336_trunk_left.rb +1 -0
  24. data/db/migrate/20130411210957_update_codenames.rb +1 -0
  25. data/db/migrate/20140822073704_create_new_revision_tables.rb +1 -0
  26. data/db/migrate/20141001105348_move_revisions_to_actions.rb +9 -3
  27. data/db/migrate/20141216053032_better_index_names.rb +9 -6
  28. data/db/migrate/20170908114442_create_delayed_jobs.rb +1 -1
  29. data/db/migrate/20170908114452_increase_text_size_for_delayed_jobs.rb +1 -1
  30. data/db/migrate/20180514152037_add_card_virtuals_table.rb +1 -1
  31. data/db/migrate_core_cards/20120611203506_rails_inflection_updates.rb +3 -2
  32. data/db/migrate_core_cards/20130411191151_renaming_for_menu.rb +9 -9
  33. data/db/migrate_core_cards/20130419215612_import_help_text.rb +3 -2
  34. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +5 -5
  35. data/db/migrate_core_cards/20130910183318_move_styles_to_content.rb +3 -2
  36. data/db/migrate_core_cards/20130920291703_update_stylesheets.rb +2 -4
  37. data/db/migrate_core_cards/20131016172445_common_css_patch.rb +1 -3
  38. data/db/migrate_core_cards/20140110193325_reset_account_request_type.rb +1 -3
  39. data/db/migrate_core_cards/20140307231621_user_data_to_cards.rb +12 -8
  40. data/db/migrate_core_cards/20140317035504_account_requests_to_signups.rb +2 -4
  41. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +16 -9
  42. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +19 -11
  43. data/db/migrate_core_cards/20140725180118_config_card_updates.rb +1 -1
  44. data/db/migrate_core_cards/20141115034214_config_descriptions_etc.rb +1 -1
  45. data/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb +1 -1
  46. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +2 -0
  47. data/db/migrate_core_cards/20141216155251_add_more_following_cards.rb +4 -2
  48. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +2 -2
  49. data/db/migrate_core_cards/20150220134731_following_to_follow_rule.rb +3 -4
  50. data/db/migrate_core_cards/20150317162412_bootstrap_themes.rb +8 -4
  51. data/db/migrate_core_cards/20150326205655_bootswatch_themes.rb +14 -7
  52. data/db/migrate_core_cards/20150429090551_search_card_context.rb +6 -4
  53. data/db/migrate_core_cards/20150508212032_menu_compatibility.rb +4 -2
  54. data/db/migrate_core_cards/20150510031118_fix_skin_codenames.rb +2 -1
  55. data/db/migrate_core_cards/20150601133433_add_recent_setting_session_card.rb +3 -3
  56. data/db/migrate_core_cards/20150610171702_add_debugger_session_card.rb +2 -1
  57. data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +4 -3
  58. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +6 -2
  59. data/db/migrate_core_cards/20150807205221_create_references_for_search_cards.rb +1 -1
  60. data/db/migrate_core_cards/20150824135418_update_file_history.rb +2 -0
  61. data/db/migrate_core_cards/20160804112510_reorganize_scripts.rb +1 -1
  62. data/db/migrate_core_cards/20160811115836_rename_stats_to_admin.rb +1 -0
  63. data/db/migrate_core_cards/20160914132636_fix_mod_files.rb +2 -0
  64. data/db/migrate_core_cards/20161102202156_tweak_recaptcha_setting_cards.rb +6 -6
  65. data/db/migrate_core_cards/20161103154836_update_keys.rb +2 -1
  66. data/db/migrate_core_cards/20170209132834_email_test_context.rb +2 -0
  67. data/db/migrate_core_cards/20170314175313_add_notification_event_card.rb +3 -3
  68. data/db/migrate_core_cards/20170515101262_add_advanced_edit_cards.rb +1 -1
  69. data/db/migrate_core_cards/20170608200649_add_input_options_codename.rb +1 -1
  70. data/db/migrate_core_cards/20180712042655_head_rule.rb +3 -4
  71. data/db/migrate_core_cards/20180905061537_migrate_layouts.rb +4 -4
  72. data/db/migrate_core_cards/20181120200937_update_layout.rb +1 -1
  73. data/db/migrate_core_cards/20190320091257_upgrade_recaptcha_to_v3.rb +7 -7
  74. data/db/migrate_core_cards/20190424100531_update_credit_image.rb +1 -0
  75. data/db/migrate_core_cards/20190502130029_add_shark_and_help_desk_role.rb +15 -14
  76. data/db/migrate_core_cards/20190503122739_update_pristine_data.rb +1 -1
  77. data/db/migrate_core_cards/20190625153616_pointer_overhaul.rb +9 -5
  78. data/db/migrate_core_cards/20190718140126_add_guides.rb +3 -3
  79. data/db/migrate_core_cards/20190822093633_move_help_text_to_code.rb +1 -2
  80. data/db/migrate_core_cards/20190823220018_cleanup_for_decko_1_0.rb +1 -1
  81. data/db/migrate_core_cards/20190829093961_cardtype_grouping.rb +7 -7
  82. data/db/migrate_core_cards/20190902193208_input_type.rb +1 -3
  83. data/db/migrate_core_cards/20190909104250_add_cardtype_input_types.rb +2 -2
  84. data/db/migrate_core_cards/20191028135243_add_link_editor_to_tiny_mce_config.rb +1 -0
  85. data/db/migrate_core_cards/20191115160748_history_cleanup.rb +0 -1
  86. data/db/migrate_core_cards/20191118145629_codename_fixes.rb +1 -2
  87. data/db/migrate_core_cards/20200821231558_add_nest_list_type.rb +1 -1
  88. data/db/migrate_core_cards/data/decko_logo.svg +1 -59
  89. data/db/seed/new/card_actions.yml +2153 -2145
  90. data/db/seed/new/card_acts.yml +3 -3
  91. data/db/seed/new/card_references.yml +900 -858
  92. data/db/seed/new/cards.yml +4869 -4848
  93. data/db/seed/new/schema_migrations_deck_cards.yml +2 -0
  94. data/db/seed/test/fixtures/card_actions.yml +3563 -3547
  95. data/db/seed/test/fixtures/card_acts.yml +675 -675
  96. data/db/seed/test/fixtures/card_changes.yml +103 -103
  97. data/db/seed/test/fixtures/card_references.yml +2165 -2123
  98. data/db/seed/test/fixtures/cards.yml +7862 -7751
  99. data/db/seed/test/fixtures/rails.gif +0 -0
  100. data/db/seed/test/fixtures/schema_migrations_deck_cards.yml +2 -0
  101. data/db/test_seed.rb +33 -34
  102. data/lib/card.rb +18 -1
  103. data/lib/card/auth.rb +5 -2
  104. data/lib/card/auth/current.rb +39 -100
  105. data/lib/card/auth/proxy.rb +36 -16
  106. data/lib/card/auth/token.rb +8 -2
  107. data/lib/card/cache.rb +2 -1
  108. data/lib/card/cache/all.rb +88 -0
  109. data/lib/card/cache/card_class.rb +44 -0
  110. data/lib/card/cache/persistent.rb +3 -34
  111. data/lib/card/cache/persistent_class.rb +28 -0
  112. data/lib/card/codename.rb +3 -4
  113. data/lib/card/content.rb +20 -10
  114. data/lib/card/content/all.rb +59 -0
  115. data/lib/card/content/chunk.rb +1 -1
  116. data/lib/card/content/clean.rb +4 -3
  117. data/lib/card/content/diff.rb +3 -2
  118. data/lib/card/content/diff/l_c_s/processor.rb +1 -1
  119. data/lib/card/content/diff/result.rb +41 -29
  120. data/lib/card/content/parser.rb +2 -2
  121. data/lib/card/content/truncate.rb +6 -6
  122. data/lib/card/director.rb +1 -1
  123. data/lib/card/director/act_direction.rb +4 -0
  124. data/lib/card/director/all.rb +61 -0
  125. data/lib/card/director/card_class.rb +18 -0
  126. data/lib/card/director/card_methods.rb +1 -0
  127. data/lib/card/director/event_delay.rb +4 -6
  128. data/lib/card/director/phases.rb +0 -1
  129. data/lib/card/director/run.rb +2 -0
  130. data/lib/card/director/stages.rb +3 -2
  131. data/lib/card/dirty.rb +13 -3
  132. data/lib/card/env.rb +2 -2
  133. data/lib/card/env/location.rb +4 -3
  134. data/lib/card/env/success.rb +46 -103
  135. data/lib/card/env/success/target.rb +73 -0
  136. data/lib/card/error.rb +1 -2
  137. data/lib/card/fetch.rb +7 -4
  138. data/lib/card/fetch/all.rb +33 -0
  139. data/lib/card/fetch/card_class.rb +155 -0
  140. data/lib/card/fetch/results.rb +9 -0
  141. data/lib/card/fetch/retrieve.rb +2 -0
  142. data/lib/card/fetch/store.rb +1 -0
  143. data/lib/card/format.rb +1 -2
  144. data/lib/card/format/content.rb +1 -3
  145. data/lib/card/format/error.rb +8 -4
  146. data/lib/card/format/method_delegation.rb +10 -2
  147. data/lib/card/format/nest.rb +3 -2
  148. data/lib/card/format/nest/fetch.rb +3 -2
  149. data/lib/card/format/nesting/mode.rb +1 -1
  150. data/lib/card/format/nesting/subformat.rb +2 -1
  151. data/lib/card/format/render.rb +2 -2
  152. data/lib/card/format/wrapper.rb +1 -1
  153. data/lib/card/lexicon.rb +5 -4
  154. data/lib/card/mark.rb +17 -15
  155. data/lib/card/model/save_helper.rb +18 -184
  156. data/lib/card/model/save_helper/save_arguments.rb +94 -0
  157. data/lib/card/model/save_helper/save_helper_helper.rb +93 -0
  158. data/lib/card/name.rb +10 -9
  159. data/lib/card/name/all.rb +136 -0
  160. data/lib/card/name/all/descendants.rb +48 -0
  161. data/lib/card/name/all/parts.rb +67 -0
  162. data/lib/card/name/card_class.rb +28 -0
  163. data/lib/card/name/fields_and_traits.rb +4 -2
  164. data/lib/card/name/name_variants.rb +0 -1
  165. data/lib/card/query.rb +24 -19
  166. data/lib/card/query/card_query/interpretation.rb +3 -2
  167. data/lib/card/query/card_query/match_attributes.rb +2 -1
  168. data/lib/card/query/card_query/normalization.rb +1 -0
  169. data/lib/card/query/card_query/reference_attributes.rb +1 -1
  170. data/lib/card/query/card_query/sorting.rb +12 -4
  171. data/lib/card/query/join.rb +1 -1
  172. data/lib/card/query/sql_statement.rb +1 -1
  173. data/lib/card/query/value/match_value.rb +1 -0
  174. data/lib/card/reference/all.rb +136 -0
  175. data/lib/card/rule/all.rb +76 -0
  176. data/lib/card/rule/cache.rb +2 -0
  177. data/lib/card/set/advanced_api.rb +8 -4
  178. data/lib/card/set/event.rb +2 -2
  179. data/lib/card/set/event/all.rb +101 -0
  180. data/lib/card/set/event/delayed_event.rb +6 -6
  181. data/lib/card/set/event/options.rb +14 -5
  182. data/lib/card/set/event/skip_and_trigger.rb +89 -0
  183. data/lib/card/set/format.rb +16 -9
  184. data/lib/card/set/format/abstract_format/view_definition.rb +1 -0
  185. data/lib/card/set/format/abstract_format/view_opts.rb +1 -0
  186. data/lib/card/set/i18n_scope.rb +18 -13
  187. data/lib/card/set/inheritance.rb +8 -6
  188. data/lib/card/set/loader.rb +24 -13
  189. data/lib/card/set/pattern/all.rb +63 -0
  190. data/lib/card/set/pattern/base.rb +4 -74
  191. data/lib/card/set/pattern/class_methods.rb +75 -0
  192. data/lib/card/set/required_field.rb +4 -1
  193. data/lib/card/set/trait.rb +11 -8
  194. data/lib/card/setting.rb +13 -12
  195. data/lib/card/subcards.rb +3 -4
  196. data/lib/card/subcards/add.rb +3 -24
  197. data/lib/card/subcards/all.rb +103 -0
  198. data/lib/card/subcards/args.rb +42 -0
  199. data/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb +1 -1
  200. data/lib/card/tasks/card/file_card_creator/output_helper.rb +17 -14
  201. data/lib/card/tasks/card/migrate.rake +2 -2
  202. data/lib/card/view/cache.rb +6 -8
  203. data/lib/card/view/cache/cache_action.rb +1 -2
  204. data/lib/card/view/cache/stub.rb +1 -1
  205. data/lib/card/view/options.rb +5 -4
  206. data/lib/card/view/permission.rb +15 -3
  207. data/lib/cardio.rb +10 -67
  208. data/lib/cardio/defaults.yml +70 -0
  209. data/lib/cardio/migration.rb +2 -2
  210. data/lib/cardio/migration/deck_structure.rb +2 -4
  211. data/lib/cardio/migration/import.rb +3 -3
  212. data/lib/cardio/migration/import/import_data.rb +1 -0
  213. data/lib/cardio/mod.rb +1 -0
  214. data/lib/cardio/mod/dirs.rb +2 -2
  215. data/lib/cardio/mod/load_strategy.rb +2 -4
  216. data/lib/cardio/mod/loader/set_loader.rb +2 -1
  217. data/lib/cardio/mod/loader/set_pattern_loader.rb +0 -1
  218. data/lib/cardio/mod/module_template.rb +1 -0
  219. data/lib/cardio/modfiles.rb +2 -4
  220. data/lib/cardio/schema.rb +2 -4
  221. data/lib/cardio/utils.rb +9 -0
  222. data/lib/generators/card/format/format_generator.rb +1 -1
  223. data/lib/generators/card/migration/migration_generator.rb +2 -1
  224. data/lib/generators/card/mod/mod_generator.rb +3 -2
  225. data/lib/generators/card/set/set_generator.rb +3 -3
  226. data/lib/generators/card/template/template_generator.rb +1 -1
  227. data/mod/admin/set/self/admin.rb +6 -3
  228. data/mod/admin/set/self/admin_info.rb +3 -8
  229. data/mod/admin/set/self/trash.rb +3 -2
  230. data/mod/admin/spec/set/self/admin_spec.rb +4 -4
  231. data/mod/core/set/all/abort.rb +5 -5
  232. data/mod/core/set/all/assign_attributes.rb +12 -28
  233. data/mod/core/set/all/autoname.rb +17 -0
  234. data/mod/core/set/all/codename.rb +3 -2
  235. data/mod/core/set/all/collection.rb +4 -6
  236. data/mod/core/set/all/content.rb +55 -99
  237. data/mod/core/set/all/contextual_content.rb +2 -4
  238. data/mod/core/set/all/initialize.rb +9 -9
  239. data/mod/core/set/all/name_events.rb +78 -58
  240. data/mod/core/set/all/reference_events.rb +69 -0
  241. data/mod/core/set/all/states.rb +5 -5
  242. data/mod/core/set/all/subcards.rb +1 -101
  243. data/mod/core/set/all/trash.rb +16 -14
  244. data/mod/core/set/all/type.rb +11 -11
  245. data/mod/core/set/all/utils.rb +4 -1
  246. data/mod/{settings → core}/set/right/autoname.rb +0 -0
  247. data/mod/{settings → core}/set/self/autoname.rb +0 -0
  248. data/mod/core/set/type/cardtype.rb +28 -0
  249. data/mod/core/set_pattern/06_rule.rb +1 -1
  250. data/mod/core/spec/set/all/assign_attributes_spec.rb +10 -9
  251. data/mod/core/spec/set/all/{rules2_spec.rb → clean_me_spec.rb} +19 -4
  252. data/mod/core/spec/set/all/collection_spec.rb +1 -1
  253. data/mod/core/spec/set/all/export_spec.rb +1 -0
  254. data/mod/core/spec/set/all/initialize_spec.rb +11 -11
  255. data/mod/core/spec/set/all/name_events_spec.rb +204 -0
  256. data/mod/{standard → core}/spec/set/type/cardtype_spec.rb +3 -24
  257. data/mod/standard/file/logo/image-original.svg +1 -59
  258. metadata +50 -61
  259. data/config/initializers/uuid_state_file.rb +0 -3
  260. data/lib/card/mod_inflector.rb +0 -16
  261. data/mod/Modfile +0 -4
  262. data/mod/core/set/all/actify.rb +0 -68
  263. data/mod/core/set/all/cache.rb +0 -109
  264. data/mod/core/set/all/event_conditions.rb +0 -172
  265. data/mod/core/set/all/fetch.rb +0 -122
  266. data/mod/core/set/all/fetch_helper.rb +0 -35
  267. data/mod/core/set/all/i18n.rb +0 -11
  268. data/mod/core/set/all/name.rb +0 -229
  269. data/mod/core/set/all/pattern.rb +0 -54
  270. data/mod/core/set/all/references.rb +0 -191
  271. data/mod/core/set/all/rename.rb +0 -33
  272. data/mod/core/set/all/rules.rb +0 -81
  273. data/mod/core/spec/set/all/actify_spec.rb +0 -58
  274. data/mod/core/spec/set/all/content_spec.rb +0 -15
  275. data/mod/core/spec/set/all/event_conditions_spec.rb +0 -217
  276. data/mod/core/spec/set/all/fetch_helper_spec.rb +0 -65
  277. data/mod/core/spec/set/all/fetch_spec.rb +0 -338
  278. data/mod/core/spec/set/all/i18n_spec.rb +0 -17
  279. data/mod/core/spec/set/all/name_spec.rb +0 -11
  280. data/mod/core/spec/set/all/pattern_spec.rb +0 -101
  281. data/mod/core/spec/set/all/permissions/reader_rules_spec.rb +0 -166
  282. data/mod/core/spec/set/all/references_spec.rb +0 -62
  283. data/mod/core/spec/set/all/rename_spec.rb +0 -189
  284. data/mod/core/spec/set/all/rules_spec.rb +0 -100
  285. data/mod/core/spec/set/all/subcards_spec.rb +0 -102
  286. data/mod/standard/set/all/rich_html/html_views/info.rb +0 -84
  287. data/mod/standard/set/type/cardtype.rb +0 -119
@@ -39,12 +39,14 @@ class Card
39
39
  def lookup_hash
40
40
  rows.each_with_object({}) do |row, hash|
41
41
  next unless (key = lookup_key row)
42
+
42
43
  hash[key] = row["rule_id"].to_i
43
44
  end
44
45
  end
45
46
 
46
47
  def lookup_key row
47
48
  return false unless (setting_code = setting_code(row))
49
+
48
50
  anchor_id = row["anchor_id"]
49
51
  return false unless (pattern_code = pattern_code(anchor_id, row))
50
52
 
@@ -10,17 +10,21 @@ class Card
10
10
  def ensure_set &block
11
11
  set_module = yield
12
12
  set_module = card_set_module_const_get(set_module) unless set_module.is_a?(Module)
13
- set_module
14
13
  rescue NameError => e
15
- if e.message =~ /uninitialized constant (?:Card::Set::)?(.+)$/
16
- define_set Regexp.last_match(1)
17
- end
14
+ define_set_from_error e
18
15
  # try again - there might be another submodule that doesn't exist
19
16
  ensure_set(&block)
20
17
  else
21
18
  set_module.extend Card::Set
22
19
  end
23
20
 
21
+ def define_set_from_error error
22
+ match = error.message.match(/uninitialized constant (?:Card::Set::)?(.+)$/)
23
+ return unless match
24
+
25
+ define_set match[1]
26
+ end
27
+
24
28
  def attachment name, args
25
29
  include_set Abstract::Attachment
26
30
  add_attributes name, "remote_#{name}_url".to_sym,
@@ -156,8 +156,8 @@ class Card
156
156
  end
157
157
  end
158
158
 
159
- def rescuing_if_integration is_integration
160
- is_integration ? rescuing_integration { yield } : yield
159
+ def rescuing_if_integration is_integration, &block
160
+ is_integration ? rescuing_integration(&block) : yield
161
161
  end
162
162
 
163
163
  # one failed integration event should not harm others.
@@ -0,0 +1,101 @@
1
+ class Card
2
+ module Set
3
+ class Event
4
+ # card methods for testing event applicability
5
+ module All
6
+ include SkipAndTrigger
7
+
8
+ def event_applies? event
9
+ return unless set_condition_applies? event.set_module, event.opts[:changing]
10
+
11
+ CONDITIONS.all? { |c| send "#{c}_condition_applies?", event, event.opts[c] }
12
+ end
13
+
14
+ private
15
+
16
+ def set_condition_applies? set_module, old_sets
17
+ return true if set_module == Card
18
+
19
+ set_condition_card(old_sets).singleton_class.include? set_module
20
+ end
21
+
22
+ def on_condition_applies? _event, actions
23
+ actions = Array(actions).compact
24
+ actions.empty? ? true : actions.include?(action)
25
+ end
26
+
27
+ # if changing name/type, the old card has no-longer-applicable set modules,
28
+ # so we create a new card to determine whether events apply.
29
+ # (note: cached condition card would ideally be cleared after all
30
+ # conditions are reviewed)
31
+ # @param old_sets [True/False] whether to use the old_sets
32
+ def set_condition_card old_sets
33
+ return self if old_sets || no_current_action?
34
+
35
+ @set_condition_card ||=
36
+ updating_sets? ? set_condition_card_with_new_set_modules : self
37
+ end
38
+
39
+ # existing card is being changed in a way that alters its sets
40
+ def updating_sets?
41
+ action == :update && real? && (type_id_is_changing? || name_is_changing?)
42
+ end
43
+
44
+ # prevents locking in set_condition_card
45
+ def no_current_action?
46
+ return false if @current_action
47
+
48
+ @set_condition_card = nil
49
+ true
50
+ end
51
+
52
+ def set_condition_card_with_new_set_modules
53
+ cc = Card.find id
54
+ cc.name = name
55
+ cc.type_id = type_id
56
+ cc.include_set_modules
57
+ end
58
+
59
+ def changed_condition_applies? _event, db_columns
60
+ return true unless action == :update
61
+
62
+ db_columns = Array(db_columns).compact
63
+ return true if db_columns.empty?
64
+
65
+ db_columns.any? { |col| single_changed_condition_applies? col }
66
+ end
67
+ alias_method :changing_condition_applies?, :changed_condition_applies?
68
+
69
+ def when_condition_applies? _event, block
70
+ case block
71
+ when Proc then block.call(self)
72
+ when Symbol then send block
73
+ else true
74
+ end
75
+ end
76
+
77
+ def single_changed_condition_applies? db_column
78
+ return true unless db_column
79
+
80
+ send "#{db_column}_is_changing?"
81
+ end
82
+
83
+ def wrong_stage opts
84
+ return false if director.stage_ok? opts
85
+
86
+ if !stage
87
+ "phase method #{method} called outside of event phases"
88
+ else
89
+ "#{opts.inspect} method #{method} called in stage #{stage}"
90
+ end
91
+ end
92
+
93
+ def wrong_action actn
94
+ return false if on_condition_applies?(nil, actn)
95
+
96
+ "on: #{actn} method #{method} called on #{action}"
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -59,9 +59,9 @@ class Card
59
59
 
60
60
  def handle_perform
61
61
  yield
62
- rescue StandardError => error
63
- Card::Error.report error, @card
64
- raise error
62
+ rescue StandardError => e
63
+ Card::Error.report e, @card
64
+ raise e
65
65
  ensure
66
66
  Director.expire
67
67
  end
@@ -121,7 +121,7 @@ class Card
121
121
  end
122
122
 
123
123
  def serialize_hash_value value
124
- value.each_with_object({}) { |(k, v), h| h[k] = serialize_value(v) }
124
+ value.transform_values { |v| serialize_value(v) }
125
125
  end
126
126
 
127
127
  def deserialize_value val, type
@@ -138,8 +138,8 @@ class Card
138
138
  end
139
139
 
140
140
  def deserialize_hash_value value
141
- value.each_with_object({}) do |(k, v), h|
142
- h[k] = deserialize_value v[:value], v[:type]
141
+ value.transform_values do |v|
142
+ deserialize_value v[:value], v[:type]
143
143
  end
144
144
  end
145
145
  end
@@ -23,13 +23,21 @@ class Card
23
23
  if condition == :when
24
24
  validate_when_value val
25
25
  else
26
- invalid = Array.wrap(val) - Api::OPTIONS[condition]
27
- return if invalid.empty?
26
+ validate_standard_condition_value condition, val
27
+ end
28
+ end
28
29
 
29
- raise ArgumentError,
30
- "invalid option#{'s' if invalid.size > 1} '#{invalid}' "\
30
+ def validate_standard_condition_value condition, val
31
+ invalid = invalid_condition_values condition, val
32
+ return if invalid.empty?
33
+
34
+ raise ArgumentError,
35
+ "invalid option#{'s' if invalid.size > 1} '#{invalid}' "\
31
36
  "for condition '#{condition}' in event '#{@event}'"
32
- end
37
+ end
38
+
39
+ def invalid_condition_values condition, val
40
+ Array.wrap(val) - Api::OPTIONS[condition]
33
41
  end
34
42
 
35
43
  def validate_when_value val
@@ -65,6 +73,7 @@ class Card
65
73
  stage = opts.delete :stage
66
74
  after_subcards = opts.delete :after_subcards
67
75
  return if opts[:after] || opts[:before] || opts[:around] || !(@stage = stage)
76
+
68
77
  # after, before, or around will override stage configuration
69
78
 
70
79
  opts[:after] = callback_name stage, after_subcards
@@ -0,0 +1,89 @@
1
+ class Card
2
+ module Set
3
+ class Event
4
+ # opt into (trigger) or out of (skip) events
5
+ module SkipAndTrigger
6
+ # force skipping this event for all cards in act
7
+ def skip_event! *events
8
+ @full_skip_hash = nil
9
+ force_events events, act_skip_hash
10
+ end
11
+
12
+ # force skipping this event for this card only
13
+ def skip_event_in_action! *events
14
+ force_events events, full_skip_hash
15
+ end
16
+
17
+ # force triggering this event (when it comes up) for all cards in act
18
+ def trigger_event! *events
19
+ @full_trigger_hash = nil
20
+ force_events events, act_trigger_hash
21
+ end
22
+
23
+ # force triggering this event (when it comes up) for this card only
24
+ def trigger_event_in_action! *events
25
+ force_events events, full_trigger_hash
26
+ end
27
+
28
+ # hash form of raw skip setting, eg { "my_event" => true }
29
+ def skip_hash
30
+ @skip_hash ||= hash_with_value skip, true
31
+ end
32
+
33
+ def trigger_hash
34
+ @trigger_hash ||= hash_with_value trigger, true
35
+ end
36
+
37
+ private
38
+
39
+ # "applies always means event can run
40
+ # so if skip_condition_applies?, we do NOT skip
41
+ def skip_condition_applies? event, allowed
42
+ return true unless (val = full_skip_hash[event.name.to_s])
43
+
44
+ allowed ? val.blank? : (val != :force)
45
+ end
46
+
47
+ def trigger_condition_applies? event, required
48
+ return true unless required
49
+
50
+ full_trigger_hash[event.name.to_s].present?
51
+ end
52
+
53
+ def full_skip_hash
54
+ @full_skip_hash ||= act_skip_hash.merge skip_in_action_hash
55
+ end
56
+
57
+ def act_skip_hash
58
+ (act_card || self).skip_hash
59
+ end
60
+
61
+ def skip_in_action_hash
62
+ hash_with_value skip_in_action, true
63
+ end
64
+
65
+ def full_trigger_hash
66
+ @full_trigger_hash ||= act_trigger_hash.merge trigger_in_action_hash
67
+ end
68
+
69
+ def trigger_in_action_hash
70
+ hash_with_value trigger_in_action, true
71
+ end
72
+
73
+ def act_trigger_hash
74
+ (act_card || self).trigger_hash
75
+ end
76
+
77
+ def hash_with_value array, value
78
+ Array.wrap(array).each_with_object({}) do |event, hash|
79
+ hash[event.to_s] = value
80
+ end
81
+ end
82
+
83
+ def force_events events, hash
84
+ events.each { |e| hash[e.to_s] = :force }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -106,20 +106,27 @@ class Card
106
106
 
107
107
  def register_set_format format_class, mod
108
108
  if all_set?
109
- all_set_format_mod! format_class, mod
109
+ register_all_set_format format_class, mod
110
110
  else
111
- format_type = abstract_set? ? :abstract_format : :nonbase_format
112
- # ready to include dynamically in set members' format singletons
113
- format_hash = modules[format_type][format_class] ||= {}
114
- format_hash[shortname] ||= []
115
- format_hash[shortname] << mod
111
+ register_standard_set_format format_class, mod
116
112
  end
117
113
  end
118
114
 
119
115
  # make mod ready to include in base (non-set-specific) format classes
120
- def all_set_format_mod! format_class, mod
121
- modules[:base_format][format_class] ||= []
122
- modules[:base_format][format_class] << mod
116
+ def register_all_set_format format_class, mod
117
+ add_to_array_val modules[:base_format], format_class, mod
118
+ end
119
+
120
+ def register_standard_set_format format_class, mod
121
+ format_type = abstract_set? ? :abstract_format : :nonbase_format
122
+ # ready to include dynamically in set members' format singletons
123
+ format_hash = modules[format_type][format_class] ||= {}
124
+ add_to_array_val format_hash, shortname, mod
125
+ end
126
+
127
+ def add_to_array_val hash, key, val
128
+ hash[key] ||= []
129
+ hash[key] << val
123
130
  end
124
131
 
125
132
  class << self
@@ -55,6 +55,7 @@ class Card
55
55
  if block_given?
56
56
  raise Card::Error::ServerError, "no blocks allowed in aliased views"
57
57
  end
58
+
58
59
  views[mod][alias_to] || begin
59
60
  raise "cannot find #{alias_to} view in #{mod}; " \
60
61
  "failed to alias #{view} from #{self}"
@@ -48,6 +48,7 @@ class Card
48
48
 
49
49
  def interpret_view_settings view, opts
50
50
  return unless opts.present?
51
+
51
52
  unknown_ok[view] = true if opts[:unknown] == true
52
53
 
53
54
  VIEW_SETTINGS.each do |setting_name|
@@ -5,11 +5,11 @@ class Card
5
5
 
6
6
  # return scope for I18n
7
7
  def scope backtrace
8
- parts = path_parts backtrace
8
+ return "lib" unless (parts = path_parts backtrace)
9
+
9
10
  index = path_set_index parts
10
11
  mod = mod_from_parts parts, index
11
- set = set_from_parts parts, index
12
- "mod.#{mod}.set.#{set}"
12
+ mod || "lib"
13
13
  end
14
14
 
15
15
  # extract the mod name from the path of a set's tmp file
@@ -27,18 +27,24 @@ class Card
27
27
 
28
28
  def mod_from_parts parts, set_index
29
29
  if tmp_files?
30
- mod_from_tmp_parts parts, set_index
30
+ mod_without_tmp_prefix parts[set_index + 1]
31
31
  else
32
- parts[set_index - 1]
32
+ mod_without_version_suffix parts[set_index - 1]
33
33
  end
34
34
  end
35
35
 
36
- def mod_from_tmp_parts parts, set_index
37
- parts[set_index + 1].gsub(/^[^-]*\-/, "")
36
+ def mod_without_version_suffix mod
37
+ mod.gsub(/-[\d.]+$/, "")
38
+ end
39
+
40
+ def mod_without_tmp_prefix mod
41
+ mod.gsub(/^[^-]*-/, "")
38
42
  end
39
43
 
40
44
  def path_parts backtrace
41
- parts = find_set_path(backtrace).split(File::SEPARATOR)
45
+ return unless (path = find_set_path backtrace)
46
+
47
+ parts = path.split File::SEPARATOR
42
48
  parts[-1] = parts.last.split(".").first
43
49
  parts
44
50
  end
@@ -76,9 +82,9 @@ class Card
76
82
 
77
83
  def find_set_path backtrace
78
84
  re = %r{(?<!card)/set/}
79
- path = backtrace.find { |line| line =~ re }
80
- raise Error, "couldn't find set path in backtrace: #{backtrace}" unless path
81
- path
85
+ backtrace.find { |line| line.match?(re) }.tap do |path|
86
+ return nil unless path
87
+ end
82
88
  end
83
89
 
84
90
  # # index of the mod part in the tmp path
@@ -98,8 +104,7 @@ class Card
98
104
 
99
105
  # index of the mod part in the path
100
106
  def path_set_index parts
101
- unless (set_index = parts.index("set")) &&
102
- parts.size >= set_index + 2
107
+ unless (set_index = parts.index("set")) && parts.size >= set_index + 2
103
108
  raise Error, "not a valid set path: #{path}"
104
109
  end
105
110
 
@@ -1,9 +1,7 @@
1
1
  class Card
2
2
  module Set
3
3
  # API to inherit other sets and their formats
4
-
5
4
  module Inheritance
6
-
7
5
  # include a set module and all its format modules
8
6
  # @param [Module] set
9
7
  # @param [Hash] opts choose the formats you want to include. You can also
@@ -66,15 +64,19 @@ class Card
66
64
 
67
65
  # iterate through each format associated with a set
68
66
  def each_format set
69
- set_type = set.abstract_set? ? :abstract : :nonbase
70
- format_type = "#{set_type}_format".to_sym
71
- modules[format_type].each_pair do |format, set_format_mod_hash|
72
- next unless (format_mods = set_format_mod_hash[set.shortname])
67
+ each_format_with_mods set do |format, mods_for_set|
68
+ next unless (format_mods = mods_for_set[set.shortname])
73
69
 
74
70
  yield format, format_mods
75
71
  end
76
72
  end
77
73
 
74
+ def each_format_with_mods set
75
+ set_type = set.abstract_set? ? :abstract : :nonbase
76
+ format_type = "#{set_type}_format".to_sym
77
+ modules[format_type].each_pair { |*args| yield(*args) }
78
+ end
79
+
78
80
  def applicable_format? format, except, only
79
81
  format_sym = Card::Format.format_sym format
80
82
  return false if except && Array(except).include?(format_sym)