Class: Spree::Preferences::StaticModelPreferences::Definition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, hash) ⇒ Definition

Returns a new instance of Definition



9
10
11
12
13
14
15
16
17
# File 'lib/spree/preferences/static_model_preferences.rb', line 9

def initialize(klass, hash)
  hash = hash.symbolize_keys
  hash.keys.each do |key|
    if !klass.defined_preferences.include?(key)
      raise "Preference #{key.inspect} is not defined on #{klass}"
    end
  end
  @preferences = hash
end

Instance Attribute Details

#preferencesObject (readonly)

Returns the value of attribute preferences



7
8
9
# File 'lib/spree/preferences/static_model_preferences.rb', line 7

def preferences
  @preferences
end

Instance Method Details

#[]=(key, value) ⇒ Object



23
24
25
# File 'lib/spree/preferences/static_model_preferences.rb', line 23

def []=(key, value)
  # ignores assignment
end

#fetch(key, &block) ⇒ Object



19
20
21
# File 'lib/spree/preferences/static_model_preferences.rb', line 19

def fetch(key, &block)
  @preferences.fetch(key, &block)
end

#to_hashObject



27
28
29
# File 'lib/spree/preferences/static_model_preferences.rb', line 27

def to_hash
  @preferences.deep_dup
end