Class: WizardSteps::Store
- Inherits:
-
Object
- Object
- WizardSteps::Store
show all
- Defined in:
- lib/wizard_steps/store.rb
Defined Under Namespace
Classes: InvalidBackingStore
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Store
Returns a new instance of Store.
8
9
10
11
12
|
# File 'lib/wizard_steps/store.rb', line 8
def initialize(data)
raise InvalidBackingStore unless data.respond_to?(:[]=)
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/wizard_steps/store.rb', line 5
def data
@data
end
|
Instance Method Details
#[](key) ⇒ Object
14
15
16
|
# File 'lib/wizard_steps/store.rb', line 14
def [](key)
data[key.to_s]
end
|
#[]=(key, value) ⇒ Object
18
19
20
|
# File 'lib/wizard_steps/store.rb', line 18
def []=(key, value)
data[key.to_s] = value
end
|
#fetch(*keys) ⇒ Object
22
23
24
|
# File 'lib/wizard_steps/store.rb', line 22
def fetch(*keys)
data.slice(*Array.wrap(keys).flatten.map(&:to_s)).stringify_keys
end
|
#persist(attributes) ⇒ Object
26
27
28
29
30
|
# File 'lib/wizard_steps/store.rb', line 26
def persist(attributes)
data.merge! attributes.stringify_keys
true
end
|
#purge! ⇒ Object
32
33
34
|
# File 'lib/wizard_steps/store.rb', line 32
def purge!
data.clear
end
|
#to_camelized_hash ⇒ Object
36
37
38
|
# File 'lib/wizard_steps/store.rb', line 36
def to_camelized_hash
data.transform_keys { |k| k.camelize(:lower).to_sym }
end
|