Module: Card::View::Options::VooApi
- Included in:
- Card::View::Options
- Defined in:
- lib/card/view/options/voo_api.rb
Overview
VooApi methods let developers use view options dynamically.
Instance Attribute Summary collapse
-
#normalized_options ⇒ Hash
readonly
-
@normalized_options are determined upon initialization and do not change after that.
-
Class Method Summary collapse
Instance Method Summary collapse
-
#items ⇒ Hash
“items”, the option used to configure views of each of a list of cards, is currently the only Hash option (thus this accessor override).
- #normalize_cache(value) ⇒ Object
- #normalize_edit(value) ⇒ Object
- #normalize_input_type(value) ⇒ Object
-
#normalize_special_options!(opts) ⇒ Object
ACCESSOR_HELPERS methods that follow the normalize_#key pattern are called by accessors (arguably that should be done during normalization!).
- #normalize_wrap(value) ⇒ Object
-
#slot_options ⇒ Hash
options to be used in data attributes of card slots (normalized options with standard keys) FIXME: what we really want is options as they were when render was called.
- #special_option_value(option_key, value) ⇒ Object
Instance Attribute Details
#normalized_options ⇒ Hash (readonly)
-
@normalized_options are determined upon initialization and do not change
after that.
11 12 13 |
# File 'lib/card/view/options/voo_api.rb', line 11 def @normalized_options end |
Class Method Details
.define_getter(option_key) ⇒ Object
25 26 27 28 29 |
# File 'lib/card/view/options/voo_api.rb', line 25 def define_getter option_key define_method option_key do [option_key] end end |
.define_setter(option_key) ⇒ Object
31 32 33 34 35 |
# File 'lib/card/view/options/voo_api.rb', line 31 def define_setter option_key define_method "#{option_key}=" do |value| [option_key] = special_option_value(option_key, value) || value end end |
.included(base) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/card/view/options/voo_api.rb', line 14 def included base # Developers can also set most options directly via accessors, # eg voo.title = "King" # :view, :show, and :hide have non-standard access (see #accessible_keys) base.accessible_keys.each do |option_key| define_getter option_key unless option_key == :items define_setter option_key end end |
Instance Method Details
#items ⇒ Hash
“items”, the option used to configure views of each of a list of cards, is currently the only Hash option (thus this accessor override)
41 42 43 |
# File 'lib/card/view/options/voo_api.rb', line 41 def items [:items] ||= {} end |
#normalize_cache(value) ⇒ Object
80 81 82 |
# File 'lib/card/view/options/voo_api.rb', line 80 def normalize_cache value value&.to_sym end |
#normalize_edit(value) ⇒ Object
76 77 78 |
# File 'lib/card/view/options/voo_api.rb', line 76 def normalize_edit value value&.to_sym end |
#normalize_input_type(value) ⇒ Object
72 73 74 |
# File 'lib/card/view/options/voo_api.rb', line 72 def normalize_input_type value value&.to_sym end |
#normalize_special_options!(opts) ⇒ Object
ACCESSOR_HELPERS methods that follow the normalize_#key pattern are called by accessors (arguably that should be done during normalization!)
61 62 63 64 65 66 |
# File 'lib/card/view/options/voo_api.rb', line 61 def opts opts.each do |option_key, value| new_value = special_option_value option_key, value opts[option_key] = new_value if new_value end end |
#normalize_wrap(value) ⇒ Object
84 85 86 87 |
# File 'lib/card/view/options/voo_api.rb', line 84 def normalize_wrap value value = value.split(",").map(&:strip) if value.is_a? String Array.wrap(value).compact.flatten end |
#slot_options ⇒ Hash
options to be used in data attributes of card slots (normalized options with standard keys) FIXME: what we really want is options as they were when render was called. normalized is wrong because it can get changed before render. live is wrong because they can get changed after. current solution is a compromise.
51 52 53 54 55 |
# File 'lib/card/view/options/voo_api.rb', line 51 def .merge(view: requested_view) .merge() .slice(*Options.slot_keys) end |
#special_option_value(option_key, value) ⇒ Object
68 69 70 |
# File 'lib/card/view/options/voo_api.rb', line 68 def special_option_value option_key, value try "normalize_#{option_key}", value end |