Class: Spree::Preferences::Configuration

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

Direct Known Subclasses

AppConfiguration

Instance Method Summary collapse

Methods included from Preferable

#clear_preferences, #get_preference, #has_preference!, #has_preference?, included, #preference_default, #preference_description, #preference_type, #preferences, #save_pending_preferences, #set_preference

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object


61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/spree/preferences/configuration.rb', line 61

def method_missing(method, *args)
  name = method.to_s.gsub('=', '')
  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:


27
28
29
# File 'app/models/spree/preferences/configuration.rb', line 27

def configure
  yield(self) if block_given?
end

#preference_cache_key(name) ⇒ Object


31
32
33
# File 'app/models/spree/preferences/configuration.rb', line 31

def preference_cache_key(name)
  [rails_cache_id, self.class.name, name].compact.join('::').underscore
end

#rails_cache_idObject


35
36
37
# File 'app/models/spree/preferences/configuration.rb', line 35

def rails_cache_id
  ENV['RAILS_CACHE_ID']
end

#resetObject


39
40
41
42
43
# File 'app/models/spree/preferences/configuration.rb', line 39

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

#set(*args) ⇒ Object


50
51
52
53
54
55
56
57
58
59
# File 'app/models/spree/preferences/configuration.rb', line 50

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

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