Class: Spree::Preferences::RuntimeConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/core/preferences/runtime_configuration.rb

Direct Known Subclasses

Core::Configuration, Configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRuntimeConfiguration



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

.defaultsObject



44
45
46
# File 'lib/spree/core/preferences/runtime_configuration.rb', line 44

def defaults
  @defaults ||= {}
end

.deprecationsObject



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

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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

#resetObject



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.extract_options!
  options.each do |name, value|
    send("#{name}=", value)
  end

  send("#{args[0]}=", args[1]) if args.size == 2
end