Module: Shoppy::Concerns::Models::Optionable

Extended by:
ActiveSupport::Concern
Included in:
Variant
Defined in:
app/models/shoppy/concerns/models/optionable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#delete_option(key) ⇒ Object

This mothos will delete the key/value pair for the give instance, if the key is founf. if not, the command will be ignored.



32
33
34
35
36
# File 'app/models/shoppy/concerns/models/optionable.rb', line 32

def delete_option(key)
  self.options.delete(key)
  self.options_will_change!
  self
end

#empty_optionObject



38
39
40
41
42
# File 'app/models/shoppy/concerns/models/optionable.rb', line 38

def empty_option
  self.options = {}
  self.options_will_change!
  self
end

#put_option(key, value) ⇒ Object

This method will add a key value paid to the model or update the value of the key, if the key is found for a given instance of the model



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/shoppy/concerns/models/optionable.rb', line 17

def put_option(key, value)
  if self.options[key] == nil
    self.options.merge!({key => value}) unless key == ""
    self.options_will_change! unless key == ""
    self
  else
    self.options[key] = value unless key == ""
    self.options_will_change! unless key == ""
    self
  end
end