3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/spree/preference_access.rb', line 3
def self.included(base)
class << base
def get(key = nil)
key = key.to_s if key.is_a?(Symbol)
return nil unless config = self.instance
prefs = Rails.cache.fetch("configuration_#{config.class.name}".to_sym) { config.preferences }
return prefs if key.nil?
prefs[key]
end
def set(preferences={})
config = self.instance
preferences.each do |key, value|
config.set_preference(key, value)
end
config.save
Rails.cache.delete("configuration_#{config.class.name}".to_sym)
end
alias_method :[], :get
end
end
|