Class: Lookbook::Store

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/lookbook/support/store.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial_data = nil, opts = {}) ⇒ Store

Returns a new instance of Store.



3
4
5
6
7
# File 'lib/lookbook/support/store.rb', line 3

def initialize(initial_data = nil, opts = {})
  @recursive = opts[:recursive] || false
  super()
  initial_data.to_h.each { |k, v| self[k] = v }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
22
# File 'lib/lookbook/support/store.rb', line 17

def method_missing(name, *args)
  if name.to_s.end_with?("=")
    args[0] = normalize_value(args[0])
  end
  super(name, *args)
end

Instance Method Details

#[]=(key, value) ⇒ Object



9
10
11
# File 'lib/lookbook/support/store.rb', line 9

def []=(key, value)
  super(key, normalize_value(value))
end

#fetch(name, *args) ⇒ Object



13
14
15
# File 'lib/lookbook/support/store.rb', line 13

def fetch(name, *args)
  super(name.to_sym, *args)
end

#respond_to_missing?(name, include_private) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/lookbook/support/store.rb', line 24

def respond_to_missing?(name, include_private)
  true
end

#to_hObject



28
29
30
31
32
# File 'lib/lookbook/support/store.rb', line 28

def to_h
  transform_values do |value|
    value.is_a?(Store) ? value.to_h : value
  end
end

#to_hashObject



34
35
36
# File 'lib/lookbook/support/store.rb', line 34

def to_hash
  to_h
end