Module: Card::View::Options::VooApi
- Included in:
- Card::View::Options
- Defined in:
- lib/card/view/options/voo_api.rb
Overview
The methods of the VooApi module allow developers to read and write 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
- #closest_live_option(key) ⇒ Object
-
#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).
-
#live_options ⇒ Hash
- @live_options are dynamic and can be altered by the "voo" API at any time.
- #normalize_cache(value) ⇒ Object
-
#normalize_editor(value) ⇒ Object
ACCESSOR_HELPERS methods that follow the normalize_#key pattern are called by accessors (arguably that should be done during normalization!).
-
#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.
Instance Attribute Details
#normalized_options ⇒ Hash (readonly)
- @normalized_options are determined upon initialization and do not change after that.
12 13 14 |
# File 'lib/card/view/options/voo_api.rb', line 12 def @normalized_options end |
Class Method Details
.define_getter(option_key) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/card/view/options/voo_api.rb', line 34 def define_getter option_key define_method option_key do norm_method = "normalize_#{option_key}" value = [option_key] try(norm_method, value) || value end end |
.define_setter(option_key) ⇒ Object
42 43 44 45 46 |
# File 'lib/card/view/options/voo_api.rb', line 42 def define_setter option_key define_method "#{option_key}=" do |value| [option_key] = value end end |
.included(base) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/card/view/options/voo_api.rb', line 23 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
#closest_live_option(key) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/card/view/options/voo_api.rb', line 68 def closest_live_option key if .key? key [key] elsif (ancestor = next_ancestor) ancestor.closest_live_option key end end |
#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)
52 53 54 |
# File 'lib/card/view/options/voo_api.rb', line 52 def items [:items] ||= {} end |
#live_options ⇒ Hash
- @live_options are dynamic and can be altered by the "voo" API at any time. Such alterations are NOT used in stubs
18 19 20 |
# File 'lib/card/view/options/voo_api.rb', line 18 def @live_options ||= end |
#normalize_cache(value) ⇒ Object
84 85 86 |
# File 'lib/card/view/options/voo_api.rb', line 84 def normalize_cache value value&.to_sym end |
#normalize_editor(value) ⇒ Object
ACCESSOR_HELPERS methods that follow the normalize_#key pattern are called by accessors (arguably that should be done during normalization!)
80 81 82 |
# File 'lib/card/view/options/voo_api.rb', line 80 def normalize_editor value value&.to_sym 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.
62 63 64 65 66 |
# File 'lib/card/view/options/voo_api.rb', line 62 def .merge(view: requested_view).select do |k, _v| Options.all_keys.include? k end end |