Class: Spree::Preferences::StaticModelPreferences

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

Defined Under Namespace

Classes: Definition

Instance Method Summary collapse

Constructor Details

#initializeStaticModelPreferences

Returns a new instance of StaticModelPreferences



32
33
34
35
36
# File 'lib/spree/preferences/static_model_preferences.rb', line 32

def initialize
  @store = Hash.new do |h, klass|
    h[klass] = {}
  end
end

Instance Method Details

#add(klass, name, preferences) ⇒ Object



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

def add(klass, name, preferences)
  # We use class name instead of class to allow reloading in dev
  raise "Static model preference '#{name}' on #{klass} is already defined" if @store[klass.to_s][name]
  @store[klass.to_s][name] = Definition.new(klass, preferences)
end

#for_class(klass) ⇒ Object



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

def for_class(klass)
  @store[klass.to_s]
end