Module: Figure::Store

Included in:
Figure, Figurine
Defined in:
lib/figure/store.rb

Instance Method Summary collapse

Instance Method Details

#[]=(k, v) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/figure/store.rb', line 5

def []=(k, v)
  unless respond_to? k
    self.class.send :define_method, k, Proc.new { self[k] }
  end

  super
end

#default(k = nil) ⇒ Object



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

def default(k=nil)
  default_store && k ? default_store[k] : self[:default]
end

#default_storeObject



35
36
37
# File 'lib/figure/store.rb', line 35

def default_store
  @default_store ||= self.class.ancestors[1].instance rescue nil
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/figure/store.rb', line 31

def has_key?(key)
  [key.to_s, key.to_sym].detect { |k| super(k) }
end

#merge!(h) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/figure/store.rb', line 17

def merge!(h)
  h.each do |k, v|
    self[k] = if v.is_a? Hash
      new_store k, v, self.class
    elsif v.is_a? Array
      v.map do |i|
        i.is_a?(Hash) ? new_store(k, i, self.class) : i
      end
    else
      v
    end
  end
end