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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Definition) initialize(klass, hash)

Returns a new instance of Definition



7
8
9
10
11
12
13
14
15
# File 'app/models/spree/preferences/static_model_preferences.rb', line 7

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

- (Object) preferences (readonly)

Returns the value of attribute preferences



5
6
7
# File 'app/models/spree/preferences/static_model_preferences.rb', line 5

def preferences
  @preferences
end

Instance Method Details

- (Object) []=(key, value)



21
22
23
# File 'app/models/spree/preferences/static_model_preferences.rb', line 21

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

- (Object) fetch(key, &block)



17
18
19
# File 'app/models/spree/preferences/static_model_preferences.rb', line 17

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

- (Object) to_hash



25
26
27
# File 'app/models/spree/preferences/static_model_preferences.rb', line 25

def to_hash
  @preferences.deep_dup
end