Module: Card::View::Options
- Included in:
- Card::View
- Defined in:
- lib/card/view/options.rb
Class Attribute Summary collapse
-
.keymap ⇒ Object
readonly
Returns the value of attribute keymap.
Instance Attribute Summary collapse
-
#normalized_options ⇒ Hash
readonly
- @normalized_options are determined upon initialization and do not change after that.
Class Method Summary collapse
-
.accessible_keys ⇒ Array
Keys that can be read or written via accessors.
-
.all_keys ⇒ Array
all standard option keys.
-
.carditect_keys ⇒ Array
keys whose values can be set by Deckers in card nests.
- .define_getter(option_key) ⇒ Object
- .define_setter(option_key) ⇒ Object
-
.heir_keys ⇒ Array
keys that follow simple standard inheritance pattern from parent views.
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.
Class Attribute Details
.keymap ⇒ Object (readonly)
Returns the value of attribute keymap.
55 56 57 |
# File 'lib/card/view/options.rb', line 55 def keymap @keymap end |
Instance Attribute Details
#normalized_options ⇒ Hash (readonly)
- @normalized_options are determined upon initialization and do not change after that.
112 113 114 |
# File 'lib/card/view/options.rb', line 112 def @normalized_options end |
Class Method Details
.accessible_keys ⇒ Array
Keys that can be read or written via accessors
79 80 81 82 83 84 85 |
# File 'lib/card/view/options.rb', line 79 def accessible_keys all_keys - [ # (all but the following) :view, # view is accessed as requested_view or ok_view and cannot be directly manipulated :show, :hide # these have a more extensive API (see Card::View::Visibility) #:items, ] end |
.all_keys ⇒ Array
all standard option keys
61 62 63 |
# File 'lib/card/view/options.rb', line 61 def all_keys @all_keys ||= keymap.each_with_object([]) { |(_k, v), a| a.push(*v) } end |
.carditect_keys ⇒ Array
keys whose values can be set by Deckers in card nests
67 68 69 |
# File 'lib/card/view/options.rb', line 67 def carditect_keys @carditect_keys ||= ::Set.new(keymap[:both]) + keymap[:carditect] end |
.define_getter(option_key) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/card/view/options.rb', line 87 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
95 96 97 98 99 |
# File 'lib/card/view/options.rb', line 95 def define_setter option_key define_method "#{option_key}=" do |value| [option_key] = value end end |
.heir_keys ⇒ Array
keys that follow simple standard inheritance pattern from parent views
73 74 75 |
# File 'lib/card/view/options.rb', line 73 def heir_keys @heir_keys ||= ::Set.new(keymap[:both]) + keymap[:heir] end |
Instance Method Details
#closest_live_option(key) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/card/view/options.rb', line 150 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)
134 135 136 |
# File 'lib/card/view/options.rb', line 134 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
117 118 119 |
# File 'lib/card/view/options.rb', line 117 def @live_options ||= end |
#normalize_cache(value) ⇒ Object
166 167 168 |
# File 'lib/card/view/options.rb', line 166 def normalize_cache value 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!)
162 163 164 |
# File 'lib/card/view/options.rb', line 162 def normalize_editor value 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.
144 145 146 147 148 |
# File 'lib/card/view/options.rb', line 144 def .merge(view: requested_view).select do |k, _v| Options.all_keys.include? k end end |