card 1.101.4 → 1.101.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) 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 +1 -3
  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 +10 -16
  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 +2 -1
  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 +1 -1
  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/seed/new/card_actions.yml +2153 -2145
  89. data/db/seed/new/card_acts.yml +3 -3
  90. data/db/seed/new/card_references.yml +900 -858
  91. data/db/seed/new/cards.yml +4869 -4848
  92. data/db/seed/new/schema_migrations_deck_cards.yml +2 -0
  93. data/db/seed/test/fixtures/card_actions.yml +3563 -3547
  94. data/db/seed/test/fixtures/card_acts.yml +675 -675
  95. data/db/seed/test/fixtures/card_changes.yml +103 -103
  96. data/db/seed/test/fixtures/card_references.yml +2165 -2123
  97. data/db/seed/test/fixtures/cards.yml +7862 -7751
  98. data/db/seed/test/fixtures/schema_migrations_deck_cards.yml +2 -0
  99. data/db/test_seed.rb +33 -34
  100. data/lib/card.rb +1 -0
  101. data/lib/card/auth/token.rb +2 -2
  102. data/lib/card/cache.rb +2 -1
  103. data/lib/card/cache/all.rb +5 -0
  104. data/lib/card/cache/card_class.rb +3 -0
  105. data/lib/card/codename.rb +1 -1
  106. data/lib/card/content.rb +4 -8
  107. data/lib/card/content/chunk.rb +1 -1
  108. data/lib/card/content/clean.rb +4 -3
  109. data/lib/card/content/diff.rb +3 -2
  110. data/lib/card/content/diff/l_c_s/processor.rb +1 -1
  111. data/lib/card/content/diff/result.rb +1 -0
  112. data/lib/card/content/parser.rb +2 -2
  113. data/lib/card/content/truncate.rb +6 -6
  114. data/lib/card/director.rb +1 -1
  115. data/lib/card/director/all.rb +2 -2
  116. data/lib/card/director/card_methods.rb +1 -0
  117. data/lib/card/director/event_delay.rb +4 -6
  118. data/lib/card/director/run.rb +2 -0
  119. data/lib/card/director/stages.rb +3 -2
  120. data/lib/card/env/location.rb +4 -3
  121. data/lib/card/fetch.rb +7 -4
  122. data/lib/card/fetch/all.rb +1 -0
  123. data/lib/card/fetch/card_class.rb +35 -27
  124. data/lib/card/fetch/results.rb +9 -0
  125. data/lib/card/fetch/retrieve.rb +2 -0
  126. data/lib/card/fetch/store.rb +1 -0
  127. data/lib/card/format/content.rb +1 -3
  128. data/lib/card/format/error.rb +6 -1
  129. data/lib/card/format/method_delegation.rb +10 -2
  130. data/lib/card/format/nest.rb +2 -1
  131. data/lib/card/format/nest/fetch.rb +2 -0
  132. data/lib/card/format/nesting/mode.rb +1 -1
  133. data/lib/card/format/nesting/subformat.rb +2 -1
  134. data/lib/card/format/render.rb +2 -2
  135. data/lib/card/format/wrapper.rb +1 -1
  136. data/lib/card/lexicon.rb +3 -2
  137. data/lib/card/mark.rb +17 -15
  138. data/lib/card/model/save_helper.rb +3 -3
  139. data/lib/card/name.rb +10 -9
  140. data/lib/card/name/all.rb +3 -0
  141. data/lib/card/name/all/descendants.rb +3 -4
  142. data/lib/card/name/card_class.rb +2 -0
  143. data/lib/card/name/fields_and_traits.rb +4 -2
  144. data/lib/card/name/name_variants.rb +0 -1
  145. data/lib/card/query.rb +17 -17
  146. data/lib/card/query/card_query/interpretation.rb +1 -0
  147. data/lib/card/query/card_query/match_attributes.rb +2 -1
  148. data/lib/card/query/card_query/normalization.rb +1 -0
  149. data/lib/card/query/card_query/reference_attributes.rb +1 -1
  150. data/lib/card/query/join.rb +1 -1
  151. data/lib/card/query/value/match_value.rb +1 -0
  152. data/lib/card/reference/all.rb +7 -2
  153. data/lib/card/rule/all.rb +1 -0
  154. data/lib/card/rule/cache.rb +2 -0
  155. data/lib/card/set/advanced_api.rb +3 -2
  156. data/lib/card/set/event.rb +2 -2
  157. data/lib/card/set/event/all.rb +6 -0
  158. data/lib/card/set/event/delayed_event.rb +6 -6
  159. data/lib/card/set/event/options.rb +1 -0
  160. data/lib/card/set/format/abstract_format/view_definition.rb +1 -0
  161. data/lib/card/set/format/abstract_format/view_opts.rb +1 -0
  162. data/lib/card/set/i18n_scope.rb +4 -2
  163. data/lib/card/set/inheritance.rb +0 -1
  164. data/lib/card/set/loader.rb +0 -2
  165. data/lib/card/set/pattern/base.rb +3 -2
  166. data/lib/card/set/pattern/class_methods.rb +2 -2
  167. data/lib/card/set/required_field.rb +4 -1
  168. data/lib/card/setting.rb +3 -0
  169. data/lib/card/subcards.rb +3 -4
  170. data/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb +1 -1
  171. data/lib/card/tasks/card/file_card_creator/output_helper.rb +2 -4
  172. data/lib/card/tasks/card/migrate.rake +2 -2
  173. data/lib/card/view/cache.rb +6 -8
  174. data/lib/card/view/cache/cache_action.rb +1 -2
  175. data/lib/card/view/cache/stub.rb +1 -1
  176. data/lib/card/view/options.rb +3 -3
  177. data/lib/card/view/permission.rb +1 -0
  178. data/lib/cardio.rb +1 -1
  179. data/lib/cardio/migration.rb +1 -1
  180. data/lib/cardio/migration/deck_structure.rb +2 -4
  181. data/lib/cardio/migration/import.rb +2 -2
  182. data/lib/cardio/migration/import/import_data.rb +1 -0
  183. data/lib/cardio/mod.rb +1 -0
  184. data/lib/cardio/mod/load_strategy.rb +2 -4
  185. data/lib/cardio/mod/loader/set_loader.rb +2 -1
  186. data/lib/cardio/mod/module_template.rb +1 -0
  187. data/lib/cardio/modfiles.rb +2 -4
  188. data/lib/cardio/schema.rb +2 -4
  189. data/lib/cardio/utils.rb +1 -0
  190. data/lib/generators/card/format/format_generator.rb +1 -1
  191. data/lib/generators/card/migration/migration_generator.rb +2 -1
  192. data/lib/generators/card/mod/mod_generator.rb +3 -2
  193. data/lib/generators/card/set/set_generator.rb +3 -3
  194. data/lib/generators/card/template/template_generator.rb +1 -1
  195. data/mod/admin/set/self/admin.rb +6 -3
  196. data/mod/admin/set/self/trash.rb +1 -0
  197. data/mod/admin/spec/set/self/admin_spec.rb +4 -4
  198. data/mod/core/set/all/abort.rb +5 -5
  199. data/mod/core/set/all/assign_attributes.rb +5 -8
  200. data/mod/core/set/all/codename.rb +1 -0
  201. data/mod/core/set/all/collection.rb +4 -6
  202. data/mod/core/set/all/content.rb +3 -2
  203. data/mod/core/set/all/contextual_content.rb +2 -4
  204. data/mod/core/set/all/name_events.rb +13 -6
  205. data/mod/core/set/all/reference_events.rb +2 -0
  206. data/mod/core/set/all/states.rb +3 -3
  207. data/mod/core/set/all/subcards.rb +1 -1
  208. data/mod/core/set/all/trash.rb +5 -1
  209. data/mod/core/set/all/type.rb +4 -2
  210. data/mod/core/set/all/utils.rb +1 -1
  211. data/mod/core/spec/set/all/assign_attributes_spec.rb +10 -9
  212. data/mod/core/spec/set/all/clean_me_spec.rb +19 -4
  213. data/mod/core/spec/set/all/collection_spec.rb +1 -1
  214. data/mod/core/spec/set/all/export_spec.rb +1 -0
  215. data/mod/core/spec/set/all/initialize_spec.rb +11 -11
  216. metadata +4 -4
data/lib/card/rule/all.rb CHANGED
@@ -24,6 +24,7 @@ class Card
24
24
 
25
25
  def preference_card_id setting_code, user=nil
26
26
  return unless (user_id = preference_user_id user)
27
+
27
28
  rule_id_lookup Card::Rule.preference_cache,
28
29
  "#{setting_code}+#{user_id}",
29
30
  "#{setting_code}+#{AllID}"
@@ -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,8 +10,8 @@ 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
- rescue NameError => error
14
- define_set_from_error error
13
+ rescue NameError => e
14
+ define_set_from_error e
15
15
  # try again - there might be another submodule that doesn't exist
16
16
  ensure_set(&block)
17
17
  else
@@ -21,6 +21,7 @@ class Card
21
21
  def define_set_from_error error
22
22
  match = error.message.match(/uninitialized constant (?:Card::Set::)?(.+)$/)
23
23
  return unless match
24
+
24
25
  define_set match[1]
25
26
  end
26
27
 
@@ -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.
@@ -31,6 +31,7 @@ class Card
31
31
  # @param old_sets [True/False] whether to use the old_sets
32
32
  def set_condition_card old_sets
33
33
  return self if old_sets || no_current_action?
34
+
34
35
  @set_condition_card ||=
35
36
  updating_sets? ? set_condition_card_with_new_set_modules : self
36
37
  end
@@ -57,8 +58,10 @@ class Card
57
58
 
58
59
  def changed_condition_applies? _event, db_columns
59
60
  return true unless action == :update
61
+
60
62
  db_columns = Array(db_columns).compact
61
63
  return true if db_columns.empty?
64
+
62
65
  db_columns.any? { |col| single_changed_condition_applies? col }
63
66
  end
64
67
  alias_method :changing_condition_applies?, :changed_condition_applies?
@@ -73,11 +76,13 @@ class Card
73
76
 
74
77
  def single_changed_condition_applies? db_column
75
78
  return true unless db_column
79
+
76
80
  send "#{db_column}_is_changing?"
77
81
  end
78
82
 
79
83
  def wrong_stage opts
80
84
  return false if director.stage_ok? opts
85
+
81
86
  if !stage
82
87
  "phase method #{method} called outside of event phases"
83
88
  else
@@ -87,6 +92,7 @@ class Card
87
92
 
88
93
  def wrong_action actn
89
94
  return false if on_condition_applies?(nil, actn)
95
+
90
96
  "on: #{actn} method #{method} called on #{action}"
91
97
  end
92
98
  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
@@ -73,6 +73,7 @@ class Card
73
73
  stage = opts.delete :stage
74
74
  after_subcards = opts.delete :after_subcards
75
75
  return if opts[:after] || opts[:before] || opts[:around] || !(@stage = stage)
76
+
76
77
  # after, before, or around will override stage configuration
77
78
 
78
79
  opts[:after] = callback_name stage, after_subcards
@@ -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|
@@ -6,6 +6,7 @@ class Card
6
6
  # return scope for I18n
7
7
  def scope backtrace
8
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
12
  mod || "lib"
@@ -33,15 +34,16 @@ class Card
33
34
  end
34
35
 
35
36
  def mod_without_version_suffix mod
36
- mod.gsub(/-[\d\.]+$/, "")
37
+ mod.gsub(/-[\d.]+$/, "")
37
38
  end
38
39
 
39
40
  def mod_without_tmp_prefix mod
40
- mod.gsub(/^[^-]*\-/, "")
41
+ mod.gsub(/^[^-]*-/, "")
41
42
  end
42
43
 
43
44
  def path_parts backtrace
44
45
  return unless (path = find_set_path backtrace)
46
+
45
47
  parts = path.split File::SEPARATOR
46
48
  parts[-1] = parts.last.split(".").first
47
49
  parts
@@ -2,7 +2,6 @@ class Card
2
2
  module Set
3
3
  # API to inherit other sets and their formats
4
4
  module Inheritance
5
-
6
5
  # include a set module and all its format modules
7
6
  # @param [Module] set
8
7
  # @param [Hash] opts choose the formats you want to include. You can also
@@ -33,8 +33,6 @@ class Card
33
33
  # tmp files that add module names (Card::Set::PATTERN::ANCHOR) and
34
34
  # extend the module with Card::Set.
35
35
 
36
- #
37
-
38
36
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
37
  # Organization Phase
40
38
 
@@ -7,6 +7,7 @@ class Card
7
7
 
8
8
  def initialize card
9
9
  return if self.class.anchorless?
10
+
10
11
  @anchor_name = self.class.anchor_name(card).to_name
11
12
  @anchor_id = find_anchor_id card
12
13
  end
@@ -17,6 +18,7 @@ class Card
17
18
 
18
19
  def module_key
19
20
  return @module_key if defined? @module_key
21
+
20
22
  @module_key = self.class.module_key anchor_codenames
21
23
  end
22
24
 
@@ -35,8 +37,7 @@ class Card
35
37
 
36
38
  def anchor_codenames
37
39
  anchor_parts.map do |part|
38
- part_id = Card.fetch_id part
39
- Card::Codename[part_id] || break
40
+ part.cardname&.code || break
40
41
  end
41
42
  end
42
43
 
@@ -35,7 +35,7 @@ class Card
35
35
  end
36
36
 
37
37
  def pattern_applies? card
38
- junction_only? ? card.name.junction? : true
38
+ junction_only? ? card.name.compound? : true
39
39
  end
40
40
 
41
41
  def anchor_parts_count
@@ -63,7 +63,7 @@ class Card
63
63
  def quick_type name
64
64
  if name.present?
65
65
  card = Card.fetch name, skip_modules: true, new: {}
66
- card.include_set_modules if card.new? && name.to_name.junction?
66
+ card.include_set_modules if card.new? && name.to_name.compound?
67
67
  card&.type_name
68
68
  else
69
69
  "RichText"
@@ -29,6 +29,7 @@ class Card
29
29
 
30
30
  def define_field_test
31
31
  return unless (test = event_test)
32
+
32
33
  method_name = field_test_name
33
34
  field_set.class_exec do
34
35
  define_method method_name do
@@ -39,13 +40,15 @@ class Card
39
40
 
40
41
  def field_test_name
41
42
  return unless event_test
43
+
42
44
  "_when_left_#{event_test}".to_sym
43
45
  end
44
46
 
45
47
  def event_test
46
48
  return @event_test unless @event_test.nil?
49
+
47
50
  test = options[:when]
48
- @event_test = test&.is_a?(Symbol) ? test : false
51
+ @event_test = test.is_a?(Symbol) ? test : false
49
52
  end
50
53
 
51
54
  def field_set
data/lib/card/setting.rb CHANGED
@@ -9,6 +9,7 @@ class Card
9
9
  # O = Card['*create'] (object)
10
10
  # accessible in E
11
11
  attr_accessor :codename
12
+
12
13
  # accessible in E and M
13
14
  mattr_accessor :groups, :preferences
14
15
 
@@ -78,6 +79,7 @@ class Card
78
79
 
79
80
  def applies_to_prototype? prototype
80
81
  return true unless applies
82
+
81
83
  applies.call(prototype)
82
84
  end
83
85
 
@@ -114,6 +116,7 @@ class Card
114
116
 
115
117
  def permitted_type_ids types
116
118
  return unless types
119
+
117
120
  type_ids = Array.wrap(types).flatten.map do |cardtype|
118
121
  Card::Codename.id cardtype
119
122
  end
data/lib/card/subcards.rb CHANGED
@@ -16,6 +16,7 @@ class Card
16
16
  include Relate
17
17
 
18
18
  attr_accessor :context_card, :keys
19
+
19
20
  def initialize context_card
20
21
  @context_card = context_card
21
22
  @keys = ::Set.new
@@ -73,10 +74,8 @@ class Card
73
74
  end.compact
74
75
  end
75
76
 
76
- def each_card
77
- cards.each do |card|
78
- yield card
79
- end
77
+ def each_card &block
78
+ cards.each(&block)
80
79
  end
81
80
 
82
81
  alias_method :each, :each_card
@@ -18,7 +18,7 @@ class Card
18
18
  end
19
19
 
20
20
  def ruby_file_name
21
- @codename + ".rb"
21
+ "#{@codename}.rb"
22
22
  end
23
23
 
24
24
  def ruby_file_content
@@ -2,15 +2,13 @@ class Card
2
2
  class FileCardCreator
3
3
  # Helper methods to write to files and the console.
4
4
  module OutputHelper
5
- def write_to_mod rel_dir, filename
5
+ def write_to_mod rel_dir, filename, &block
6
6
  dir = File.join "mod", @mod, rel_dir
7
7
  FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
8
8
 
9
9
  path = File.join dir, filename
10
10
  log_file_action path do
11
- File.open(path, "w") do |opened_file|
12
- yield(opened_file)
13
- end
11
+ File.open(path, "w", &block)
14
12
  end
15
13
  end
16
14
 
@@ -24,7 +24,7 @@ def reset_column_information mod=false
24
24
  end
25
25
 
26
26
  def load_mod_lib
27
- Dir.glob(Cardio.root.join("mod/*/lib/*.rb")).each { |x| require x }
27
+ Dir.glob(Cardio.root.join("mod/*/lib/*.rb")).sort.each { |x| require x }
28
28
  end
29
29
 
30
30
  def without_dumping
@@ -100,7 +100,7 @@ namespace :card do
100
100
 
101
101
  Cardio.schema_mode args[:type] do
102
102
  version = ActiveRecord::Migrator.current_version
103
- if version.to_i > 0 && (file = ::File.open(stamp_file, "w"))
103
+ if version.to_i.positive? && (file = ::File.open(stamp_file, "w"))
104
104
  puts ">> writing version: #{version} to #{stamp_file}"
105
105
  file.puts version
106
106
  end
@@ -194,8 +194,8 @@ class Card
194
194
  # those stubs.
195
195
  #
196
196
  # @return [String (usually)] rendered view
197
- def cache_render
198
- cached_view = cache_fetch { yield }
197
+ def cache_render &block
198
+ cached_view = cache_fetch(&block)
199
199
  cache_active? ? cached_view : format.stub_render(cached_view)
200
200
  end
201
201
 
@@ -212,18 +212,16 @@ class Card
212
212
 
213
213
  # If view is cached, retrieve it. Otherwise render and store it.
214
214
  # Uses the primary cache API.
215
- def cache_fetch
215
+ def cache_fetch &block
216
216
  caching do
217
217
  ensure_cache_key
218
- self.class.cache.fetch cache_key do
219
- yield
220
- end
218
+ self.class.cache.fetch cache_key, &block
221
219
  end
222
220
  end
223
221
 
224
222
  # keep track of nested cache fetching
225
- def caching
226
- self.class.caching(self) { yield }
223
+ def caching &block
224
+ self.class.caching(self, &block)
227
225
  end
228
226
 
229
227
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -14,12 +14,11 @@ class Card
14
14
  end
15
15
 
16
16
  def log_cache_action
17
- action = yield
17
+ yield
18
18
  # TODO: make configurable
19
19
  # ...or better yet, integrate into performance logger...
20
20
  # Rails.logger.warn "VIEW CACHE #{cache_active? ? '-->' : ''}[#{action}] "\
21
21
  # "(#{card.name}##{requested_view})"
22
- action
23
22
  end
24
23
 
25
24
  # @return [Symbol] :off, :active, or :free
@@ -17,7 +17,7 @@ class Card
17
17
  end
18
18
 
19
19
  def bin_to_hex string
20
- string.unpack("H*").first
20
+ string.unpack1("H*")
21
21
  end
22
22
 
23
23
  # @return [Hash]
@@ -51,11 +51,11 @@ class Card
51
51
  :structure, # overrides the content of the card
52
52
  :title, # overrides the name of the card
53
53
  :variant, # override the canonical version of the name with a different
54
- # variant
54
+ # variant
55
55
  :input_type, # inline_nests makes a form within standard content (Symbol)
56
56
  :type, # set the default type of new cards
57
57
  :size, # set an image size
58
- # (also used for character limit in one_line_content)
58
+ # (also used for character limit in one_line_content)
59
59
  :params, # parameters for add button. deprecated!
60
60
  :items, # options for items (Hash)
61
61
  :cache, # change view cache behaviour
@@ -71,7 +71,7 @@ class Card
71
71
  :layout #
72
72
  ]
73
73
  }
74
- # Note: option values are strings unless otherwise noted
74
+ # NOTE: option values are strings unless otherwise noted
75
75
 
76
76
  class << self
77
77
  attr_reader :keymap