Class: Spree::Preferences::Configuration

Inherits:
Object
  • Object
show all
Includes:
Preferable
Defined in:
lib/spree/core/preferences/configuration.rb

Direct Known Subclasses

Core::Configuration

Instance Method Summary collapse

Methods included from Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/spree/core/preferences/configuration.rb', line 58

def method_missing(method, *args)
  name = method.to_s.delete('=')
  if has_preference? name
    if method.to_s =~ /=$/
      set_preference(name, args.first)
    else
      get_preference name
    end
  else
    super
  end
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



30
31
32
# File 'lib/spree/core/preferences/configuration.rb', line 30

def configure
  yield(self) if block_given?
end

#preferencesObject



34
35
36
# File 'lib/spree/core/preferences/configuration.rb', line 34

def preferences
  ::Spree::Preferences::ScopedStore.new(self.class.name.underscore)
end

#resetObject



38
39
40
41
42
# File 'lib/spree/core/preferences/configuration.rb', line 38

def reset
  preferences.each do |name, _value|
    set_preference name, preference_default(name)
  end
end

#set(*args) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/spree/core/preferences/configuration.rb', line 49

def set(*args)
  options = args.extract_options!
  options.each do |name, value|
    set_preference name, value
  end

  set_preference args[0], args[1] if args.size == 2
end