card 1.93.6 → 1.93.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/02_patches/active_record.rb +13 -0
  4. data/config/initializers/patches.rb +6 -0
  5. data/config/initializers/recaptcha.rb +16 -14
  6. data/lib/card.rb +4 -3
  7. data/lib/card/format/nest/fetch.rb +1 -3
  8. data/lib/card/migration/deck_structure.rb +18 -0
  9. data/lib/card/query/attributes.rb +1 -1
  10. data/lib/card/query/clause.rb +6 -7
  11. data/lib/card/query/interpretation.rb +5 -1
  12. data/lib/card/query/value.rb +29 -19
  13. data/lib/card/set/event.rb +52 -28
  14. data/lib/card/set/event/delayed_event.rb +3 -3
  15. data/lib/card/set/format/haml_views.rb +1 -1
  16. data/lib/card/tasks/card.rake +7 -0
  17. data/lib/card/tasks/card/migrate.rake +29 -0
  18. data/lib/card/view/options.rb +7 -189
  19. data/lib/card/view/options/key_lists.rb +41 -0
  20. data/lib/card/view/options/voo_api.rb +165 -0
  21. data/lib/cardio.rb +16 -7
  22. data/lib/cardio/schema.rb +6 -1
  23. data/mod/basic_formats/set/all/base.rb +7 -3
  24. data/mod/basic_formats/set/self/head.rb +5 -0
  25. data/mod/carrierwave/config/core_initializers/carrierwave.rb +7 -0
  26. data/mod/core/set/all/name_validations.rb +3 -4
  27. data/mod/machines/file/all_script_machine_output/file.js +75 -23
  28. data/mod/machines/file/all_style_machine_output/file.css +2 -2
  29. data/mod/machines/lib/javascript/decko.js.coffee +1 -1
  30. data/mod/machines/lib/javascript/decko_filter.js.coffee +18 -10
  31. data/mod/pointer/set/abstract/02_pointer.rb +1 -1
  32. data/mod/pointer/set/abstract/02_pointer/filtered.rb +3 -1
  33. data/mod/pointer/template/abstract/02_pointer/filtered/filter_items.haml +2 -1
  34. data/mod/pointer/template/abstract/02_pointer/filtered/filtered_list_input.haml +3 -2
  35. data/mod/search/set/abstract/01_filter_form_helper.rb +8 -0
  36. data/mod/search/set/abstract/{01_search_params.rb → 02_search_params.rb} +0 -0
  37. data/mod/search/set/abstract/03_filter.rb +1 -1
  38. data/mod/search/set/abstract/wql_search.rb +7 -0
  39. data/mod/search/template/abstract/03_filter/filter_form.haml +24 -22
  40. data/mod/search/template/abstract/search/checkbox_item.haml +1 -1
  41. metadata +9 -6
  42. data/mod/search/set/abstract/02_filter_formgroups.rb +0 -134
@@ -1,8 +1,7 @@
1
1
  class Card
2
2
  class View
3
+ # Manages options for card views, including those used in nest syntax
3
4
  module Options
4
- # Manages options for card views, including those used in nest syntax
5
-
6
5
  # the keymap represents a 2x2 matrix, where the factors are
7
6
  # (a) whether an option's value can be set by a Carditect via nests, and
8
7
  # (b) whether nested views can inherit the option from a parent view.
@@ -13,7 +12,6 @@ class Card
13
12
  # don't inherit | carditect | none
14
13
  #
15
14
  # (note: each option will likely some day merit its own object)
16
-
17
15
  @keymap = {
18
16
  carditect: [
19
17
  :view, # view to render
@@ -48,198 +46,18 @@ class Card
48
46
  }
49
47
  # Note: option values are strings unless otherwise noted
50
48
 
51
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
- # CLASS METHODS
53
-
54
49
  class << self
55
50
  attr_reader :keymap
56
51
 
57
- # KEY LISTS
58
-
59
- # all standard option keys
60
- # @return [Array]
61
- def all_keys
62
- @all_keys ||= keymap.each_with_object([]) { |(_k, v), a| a.push(*v) }
63
- end
64
-
65
- # keys whose values can be set by Deckers in card nests
66
- # @return [Array]
67
- def carditect_keys
68
- @carditect_keys ||= ::Set.new(keymap[:both]) + keymap[:carditect]
69
- end
70
-
71
- # keys that follow simple standard inheritance pattern from parent views
72
- # @return [Array]
73
- def heir_keys
74
- @heir_keys ||= ::Set.new(keymap[:both]) + keymap[:heir]
75
- end
76
-
77
- # Keys that can be read or written via accessors
78
- # @return [Array]
79
- def accessible_keys
80
- all_keys - [ # (all but the following)
81
- :view, # view is accessed as requested_view or ok_view and cannot be directly manipulated
82
- :show, :hide # these have a more extensive API (see Card::View::Visibility)
83
- #:items,
84
- ]
85
- end
86
-
87
- def define_getter option_key
88
- define_method option_key do
89
- norm_method = "normalize_#{option_key}"
90
- value = live_options[option_key]
91
- try(norm_method, value) || value
92
- end
93
- end
94
-
95
- def define_setter option_key
96
- define_method "#{option_key}=" do |value|
97
- live_options[option_key] = value
98
- end
99
- end
100
- end
101
-
102
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
- # VOO API
104
-
105
- # The following methods allow developers to read and write options dynamically.
106
-
107
-
108
- # There are two primary options hashes:
109
-
110
- # - @normalized_options are determined upon initialization and do not change after that.
111
- # @return [Hash] options
112
- attr_reader :normalized_options
113
-
114
- # - @live_options are dynamic and can be altered by the "voo" API at any time. Such alterations are
115
- # NOT used in stubs
116
- # @return [Hash]
117
- def live_options
118
- @live_options ||= process_live_options
119
- end
120
-
121
-
122
- # Developers can also set most options directly via accessors, eg voo.title = "King"
123
- # :view, :show, and :hide have non-standard access (see #accessible_keys)
124
-
125
- accessible_keys.each do |option_key|
126
- define_getter option_key
127
- define_setter option_key
128
- end
129
-
130
-
131
- # "items", the option used to configure views of each of a list of cards, is
132
- # currently the only Hash option (thus this accessor override)
133
- # @return [Hash]
134
- def items
135
- live_options[:items] ||= {}
136
- end
137
-
138
- # options to be used in data attributes of card slots (normalized options
139
- # with standard keys)
140
- # FIXME: what we really want is options as they were when render was called.
141
- # normalized is wrong because it can get changed before render. live is wrong
142
- # because they can get changed after. current solution is a compromise.
143
- # @return [Hash]
144
- def slot_options
145
- normalized_options.merge(view: requested_view).select do |k, _v|
146
- Options.all_keys.include? k
147
- end
148
- end
149
-
150
- def closest_live_option key
151
- if live_options.key? key
152
- live_options[key]
153
- elsif (ancestor = next_ancestor)
154
- ancestor.closest_live_option key
155
- end
156
- end
157
-
158
- # ACCESSOR_HELPERS
159
- # methods that follow the normalize_#{key} pattern are called by accessors
160
- # (arguably that should be done during normalization!)
161
-
162
- def normalize_editor value
163
- value && value.to_sym
164
- end
165
-
166
- def normalize_cache value
167
- value && value.to_sym
168
- end
169
-
170
- private
171
-
172
- # option normalization includes standardizing options into a hash with
173
- # symbols as keys, managing standard view inheritance, and special
174
- # handling for main_views.
175
- def normalize_options
176
- @normalized_options = opts = options_to_hash @raw_options.clone
177
- opts[:view] = @raw_view
178
- inherit_from_parent if parent
179
- opts[:main] = true if format.main?
180
- @optional = opts.delete(:optional) || false
181
- opts
182
- end
183
-
184
- # typically options are already a hash. this also handles an array of
185
- # hashes and nil.
186
- def options_to_hash opts
187
- case opts
188
- when ActionController::Parameters
189
- opts.to_unsafe_h.deep_symbolize_keys
190
- when Hash then opts.deep_symbolize_keys!
191
- when Array then opts[0].merge(opts[1]).deep_symbolize_keys!
192
- when nil then {}
193
- else raise Card::Error, "bad view options: #{opts}"
52
+ def add_option name, type
53
+ raise "invalid option type" unless @keymap.key?(type)
54
+ @keymap[type] << name
55
+ reset_key_lists
194
56
  end
195
57
  end
196
58
 
197
- # standard inheritance from parent view object
198
- def inherit_from_parent
199
- Options.heir_keys.each do |key|
200
- parent_value = parent.live_options[key]
201
- normalized_options[key] ||= parent_value if parent_value
202
- end
203
- end
204
-
205
- def process_live_options
206
- opts = @live_options = normalized_options.clone
207
- opts.merge! format.main_nest_options if opts[:main_view]
208
- # main_nest_options are not processed in normalize_options so that they're NOT locked in the stub.
209
- process_default_options
210
- process_visibility_options
211
- opts
212
- end
213
-
214
- # This method triggers the default_X_args methods which can alter the
215
- # @live_options hash both directly and indirectly (via the voo API)
216
- def process_default_options
217
- format.view_options_with_defaults requested_view, live_options
218
- end
219
-
220
- # "foreign" options are non-standard options. They're allowed, but they
221
- # prevent independent caching (and thus stubbing)
222
-
223
- # non-standard options that are found in normalized_options
224
- # @return [Hash] options Hash
225
- def foreign_normalized_options
226
- @foreign_normalize_options ||= foreign_options_in normalized_options
227
- end
228
-
229
- # non-standard options that are found in live_options
230
- # @return [Hash] options Hash
231
- def foreign_live_options
232
- foreign_options_in live_options
233
- end
234
-
235
- # find non-standard option in Hash
236
- # @param opts [Hash] options hash
237
- # @return [Hash] options Hash
238
- def foreign_options_in opts
239
- opts.reject { |k, _v| Options.all_keys.include? k }
240
- end
241
-
242
-
59
+ extend KeyLists
60
+ include VooApi
243
61
  end
244
62
  end
245
63
  end
@@ -0,0 +1,41 @@
1
+ class Card
2
+ class View
3
+ module Options
4
+ module KeyLists
5
+ # all standard option keys
6
+ # @return [Array]
7
+ def all_keys
8
+ @all_keys ||= keymap.each_with_object([]) { |(_k, v), a| a.push(*v) }
9
+ end
10
+
11
+ # keys whose values can be set by Deckers in card nests
12
+ # @return [Array]
13
+ def carditect_keys
14
+ @carditect_keys ||= ::Set.new(keymap[:both]) + keymap[:carditect]
15
+ end
16
+
17
+ # keys that follow simple standard inheritance pattern from parent views
18
+ # @return [Array]
19
+ def heir_keys
20
+ @heir_keys ||= ::Set.new(keymap[:both]) + keymap[:heir]
21
+ end
22
+
23
+ # Keys that can be read or written via accessors
24
+ # @return [Array]
25
+ def accessible_keys
26
+ all_keys - [ # (all but the following)
27
+ :view, # view is accessed as requested_view or ok_view and cannot be
28
+ # directly manipulated
29
+ :show, :hide # these have a more extensive API (see Card::View::Visibility)
30
+ ]
31
+ end
32
+
33
+ def reset_key_lists
34
+ @all_keys = nil
35
+ @carditect_keys = nil
36
+ @heir_keys = nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,165 @@
1
+ class Card
2
+ class View
3
+ module Options
4
+ # The methods of the VooApi module allow developers
5
+ # to read and write options dynamically.
6
+ module VooApi
7
+ # There are two primary options hashes:
8
+
9
+ # - @normalized_options are determined upon initialization and do not change
10
+ # after that.
11
+ # @return [Hash] options
12
+ attr_reader :normalized_options
13
+
14
+ # - @live_options are dynamic and can be altered by the "voo" API at any time.
15
+ # Such alterations are
16
+ # NOT used in stubs
17
+ # @return [Hash]
18
+ def live_options
19
+ @live_options ||= process_live_options
20
+ end
21
+
22
+ class << self
23
+ def included base
24
+ # Developers can also set most options directly via accessors,
25
+ # eg voo.title = "King"
26
+ # :view, :show, and :hide have non-standard access (see #accessible_keys)
27
+
28
+ base.accessible_keys.each do |option_key|
29
+ define_getter option_key unless option_key == :items
30
+ define_setter option_key
31
+ end
32
+ end
33
+
34
+ def define_getter option_key
35
+ define_method option_key do
36
+ norm_method = "normalize_#{option_key}"
37
+ value = live_options[option_key]
38
+ try(norm_method, value) || value
39
+ end
40
+ end
41
+
42
+ def define_setter option_key
43
+ define_method "#{option_key}=" do |value|
44
+ live_options[option_key] = value
45
+ end
46
+ end
47
+ end
48
+
49
+ # "items", the option used to configure views of each of a list of cards, is
50
+ # currently the only Hash option (thus this accessor override)
51
+ # @return [Hash]
52
+ def items
53
+ live_options[:items] ||= {}
54
+ end
55
+
56
+ # options to be used in data attributes of card slots (normalized options
57
+ # with standard keys)
58
+ # FIXME: what we really want is options as they were when render was called.
59
+ # normalized is wrong because it can get changed before render. live is wrong
60
+ # because they can get changed after. current solution is a compromise.
61
+ # @return [Hash]
62
+ def slot_options
63
+ normalized_options.merge(view: requested_view).select do |k, _v|
64
+ Options.all_keys.include? k
65
+ end
66
+ end
67
+
68
+ def closest_live_option key
69
+ if live_options.key? key
70
+ live_options[key]
71
+ elsif (ancestor = next_ancestor)
72
+ ancestor.closest_live_option key
73
+ end
74
+ end
75
+
76
+ # ACCESSOR_HELPERS
77
+ # methods that follow the normalize_#{key} pattern are called by accessors
78
+ # (arguably that should be done during normalization!)
79
+
80
+ def normalize_editor value
81
+ value&.to_sym
82
+ end
83
+
84
+ def normalize_cache value
85
+ value&.to_sym
86
+ end
87
+
88
+ private
89
+
90
+ # option normalization includes standardizing options into a hash with
91
+ # symbols as keys, managing standard view inheritance, and special
92
+ # handling for main_views.
93
+ def normalize_options
94
+ @normalized_options = opts = options_to_hash @raw_options.clone
95
+ opts[:view] = @raw_view
96
+ inherit_from_parent if parent
97
+ opts[:main] = true if format.main?
98
+ @optional = opts.delete(:optional) || false
99
+ opts
100
+ end
101
+
102
+ # typically options are already a hash. this also handles an array of
103
+ # hashes and nil.
104
+ def options_to_hash opts
105
+ case opts
106
+ when ActionController::Parameters
107
+ opts.to_unsafe_h.deep_symbolize_keys
108
+ when Hash then opts.deep_symbolize_keys!
109
+ when Array then opts[0].merge(opts[1]).deep_symbolize_keys!
110
+ when nil then {}
111
+ else raise Card::Error, "bad view options: #{opts}"
112
+ end
113
+ end
114
+
115
+ # standard inheritance from parent view object
116
+ def inherit_from_parent
117
+ Options.heir_keys.each do |key|
118
+ parent_value = parent.live_options[key]
119
+ normalized_options[key] ||= parent_value if parent_value
120
+ end
121
+ end
122
+
123
+ def process_live_options
124
+ @live_options = normalized_options.clone
125
+ if @live_options[:main_view]
126
+ @live_options.merge! format.main_nest_options
127
+ end
128
+ # main_nest_options are not processed in normalize_options so that
129
+ # they're NOT locked in the stub.
130
+ process_default_options
131
+ process_visibility_options
132
+ @live_options
133
+ end
134
+
135
+ # This method triggers the default_X_args methods which can alter the
136
+ # @live_options hash both directly and indirectly (via the voo API)
137
+ def process_default_options
138
+ format.view_options_with_defaults requested_view, live_options
139
+ end
140
+
141
+ # "foreign" options are non-standard options. They're allowed, but they
142
+ # prevent independent caching (and thus stubbing)
143
+
144
+ # non-standard options that are found in normalized_options
145
+ # @return [Hash] options Hash
146
+ def foreign_normalized_options
147
+ @foreign_normalize_options ||= foreign_options_in normalized_options
148
+ end
149
+
150
+ # non-standard options that are found in live_options
151
+ # @return [Hash] options Hash
152
+ def foreign_live_options
153
+ foreign_options_in live_options
154
+ end
155
+
156
+ # find non-standard option in Hash
157
+ # @param opts [Hash] options hash
158
+ # @return [Hash] options Hash
159
+ def foreign_options_in opts
160
+ opts.reject { |k, _v| Options.all_keys.include? k }
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -5,7 +5,7 @@ djar = "delayed_job_active_record"
5
5
  require djar if Gem::Specification.find_all_by_name(djar).any?
6
6
  require "cardio/schema.rb"
7
7
 
8
- ActiveSupport.on_load :card do
8
+ ActiveSupport.on_load :after_card do
9
9
  if Card.take
10
10
  Card::Mod.load
11
11
  else
@@ -128,6 +128,7 @@ module Cardio
128
128
  add_path "db"
129
129
  add_path "db/migrate"
130
130
  add_path "db/migrate_core_cards"
131
+ add_path "db/migrate_deck", root: root, with: "db/migrate"
131
132
  add_path "db/migrate_deck_cards", root: root, with: "db/migrate_cards"
132
133
  add_path "db/seeds.rb", with: "db/seeds.rb"
133
134
  end
@@ -135,6 +136,9 @@ module Cardio
135
136
  def add_initializer_paths
136
137
  add_path "config/initializers", glob: "**/*.rb"
137
138
  add_initializers root
139
+ each_mod_path do |mod_path|
140
+ add_initializers mod_path, false, "core_initializers"
141
+ end
138
142
  end
139
143
 
140
144
  def add_mod_initializer_paths
@@ -144,8 +148,8 @@ module Cardio
144
148
  end
145
149
  end
146
150
 
147
- def add_initializers dir, mod=false
148
- Dir.glob("#{dir}/config/initializers").each do |initializers_dir|
151
+ def add_initializers base_dir, mod=false, init_dir="initializers"
152
+ Dir.glob("#{base_dir}/config/#{init_dir}").each do |initializers_dir|
149
153
  path_mark = mod ? "mod/config/initializers" : "config/initializers"
150
154
  paths[path_mark] << initializers_dir
151
155
  end
@@ -184,14 +188,19 @@ module Cardio
184
188
  def migration_paths type
185
189
  list = paths["db/migrate#{schema_suffix type}"].to_a
186
190
  if type == :deck_cards
187
- Card::Mod.dirs.each("db/migrate_cards") do |path|
188
- list += Dir.glob path
189
- end
191
+ add_mod_migration_paths list
192
+ elsif type == :deck
193
+ add_mod_migration_paths list, "migrate"
190
194
  end
191
-
192
195
  list.flatten
193
196
  end
194
197
 
198
+ def add_mod_migration_paths list, dir="migrate_cards"
199
+ Card::Mod.dirs.each("db/#{dir}") do |path|
200
+ list += Dir.glob path
201
+ end
202
+ end
203
+
195
204
  private
196
205
 
197
206
  def mod_name_from_gem_spec gem_spec