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.



54
55
56
# File 'lib/card/view/options.rb', line 54

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



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

def normalized_options
  @normalized_options
end

Class Method Details

.accessible_keysArray

Keys that can be read or written via accessors

Returns:

  • (Array)


78
79
80
81
82
83
84
# File 'lib/card/view/options.rb', line 78

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)


60
61
62
# File 'lib/card/view/options.rb', line 60

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 Wagneers in card nests

Returns:

  • (Array)


66
67
68
# File 'lib/card/view/options.rb', line 66

def carditect_keys
  @carditect_keys ||= ::Set.new(keymap[:both]) + keymap[:carditect]
end

.define_getter(option_key) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/card/view/options.rb', line 86

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



94
95
96
97
98
# File 'lib/card/view/options.rb', line 94

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)


72
73
74
# File 'lib/card/view/options.rb', line 72

def heir_keys
  @heir_keys ||= ::Set.new(keymap[:both]) + keymap[:heir]
end

Instance Method Details

#closest_live_option(key) ⇒ Object



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

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)


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

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)


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

def live_options
  @live_options ||= process_live_options
end

#normalize_cache(value) ⇒ Object



160
161
162
# File 'lib/card/view/options.rb', line 160

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!)



156
157
158
# File 'lib/card/view/options.rb', line 156

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)

Returns:

  • (Hash)


140
141
142
# File 'lib/card/view/options.rb', line 140

def slot_options
  normalized_options.select { |k, _v| Options.all_keys.include? k }
end