Class: Wardrobe::Store

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wardrobe/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



8
9
10
11
# File 'lib/wardrobe/store.rb', line 8

def initialize
  @store = {}
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **key_args, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/wardrobe/store.rb', line 30

def method_missing(name, *args, **key_args, &block)
  if (atr = store[name])
    atr
  else
    super
  end
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/wardrobe/store.rb', line 6

def parent
  @parent
end

#storeObject (readonly)

Returns the value of attribute store.



6
7
8
# File 'lib/wardrobe/store.rb', line 6

def store
  @store
end

Instance Method Details

#[](name) ⇒ Object



17
18
19
# File 'lib/wardrobe/store.rb', line 17

def [](name)
  store[name]
end

#del(name) ⇒ Object



46
47
48
49
50
# File 'lib/wardrobe/store.rb', line 46

def del(name)
  mutate do
    store.delete(name) { |key| raise "#{key} not found" }
  end
end

#each(&blk) ⇒ Object



21
22
23
# File 'lib/wardrobe/store.rb', line 21

def each(&blk)
  store.each(&blk)
end

#freezeObject



25
26
27
28
# File 'lib/wardrobe/store.rb', line 25

def freeze
  store.freeze
  super
end

#merge(other, _calling_object, _config) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/wardrobe/store.rb', line 38

def merge(other, _calling_object, _config)
  mutate do
    @store = store.merge(other.store)
    # I guess we have to loop through each item and do a custom merge...
    # maybe not use Hash#merge?
  end
end

#valuesObject



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

def values
  store.values
end