Module: Card::View::Options

Included in:
Card::View
Defined in:
lib/card/view/options.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.keymapObject (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_optionsHash (readonly)

  • @normalized_options are determined upon initialization and do not change after that.

Returns:

  • (Hash)

    options



112
113
114
# File 'lib/card/view/options.rb', line 112

def normalized_options
  @normalized_options
end

Class Method Details

.accessible_keysArray

Keys that can be read or written via accessors

Returns:

  • (Array)


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_keysArray

all standard option keys

Returns:

  • (Array)


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_keysArray

keys whose values can be set by Deckers in card nests

Returns:

  • (Array)


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 = live_options[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|
    live_options[option_key] = value
  end
end

.heir_keysArray

keys that follow simple standard inheritance pattern from parent views

Returns:

  • (Array)


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 live_options.key? key
    live_options[key]
  elsif (ancestor = next_ancestor)
    ancestor.closest_live_option key
  end
end

#itemsHash

"items", the option used to configure views of each of a list of cards, is currently the only Hash option (thus this accessor override)

Returns:

  • (Hash)


134
135
136
# File 'lib/card/view/options.rb', line 134

def items
  live_options[:items] ||= {}
end

#live_optionsHash

  • @live_options are dynamic and can be altered by the "voo" API at any time. Such alterations are NOT used in stubs

Returns:

  • (Hash)


117
118
119
# File 'lib/card/view/options.rb', line 117

def live_options
  @live_options ||= process_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_optionsHash

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.

Returns:

  • (Hash)


144
145
146
147
148
# File 'lib/card/view/options.rb', line 144

def slot_options
  normalized_options.merge(view: requested_view).select do |k, _v|
    Options.all_keys.include? k
  end
end