Class: Spree::Preferences::RuntimeConfiguration
- Inherits:
-
Object
- Object
- Spree::Preferences::RuntimeConfiguration
show all
- Defined in:
- lib/spree/core/preferences/runtime_configuration.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
4
5
6
7
8
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 4
def initialize
self.class.defaults.each do |key, value|
self[key] = value
end
end
|
Class Method Details
.defaults ⇒ Object
44
45
46
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 44
def defaults
@defaults ||= {}
end
|
.deprecations ⇒ Object
48
49
50
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 48
def deprecations
@deprecations ||= {}
end
|
.preference(name, _type, default: nil, deprecated: false) ⇒ Object
38
39
40
41
42
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 38
def preference(name, _type, default: nil, deprecated: false)
defaults[name] = default
deprecations[name] = deprecated
attr_accessor name
end
|
Instance Method Details
16
17
18
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 16
def configure
yield(self) if block_given?
end
|
#get(preference) ⇒ Object
Also known as:
[]
20
21
22
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 20
def get(preference)
send(preference)
end
|
#reset ⇒ Object
10
11
12
13
14
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 10
def reset
self.class.defaults.each do |key, value|
self[key] = value
end
end
|
#set(*args) ⇒ Object
Also known as:
[]=
26
27
28
29
30
31
32
33
|
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 26
def set(*args)
options = args.
options.each do |name, value|
send("#{name}=", value)
end
send("#{args[0]}=", args[1]) if args.size == 2
end
|