Module: Shoppy::Concerns::Models::Hashable

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#delete_hash(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/hashable.rb', line 32

def delete_hash(key)
  self.hash_data.delete(key)
  self.hash_data_will_change!
  self
end

#empty_hashObject



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

def empty_hash
  self.hash_data = {}
  self.hash_data_will_change!
  self
end

#put_hash(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/hashable.rb', line 17

def put_hash(key, value)
  if self.hash_data[key] == nil
    self.hash_data.merge!({key => value}) unless key == ""
    self.hash_data_will_change! unless key == ""
    self
  else
    self.hash_data[key] = value unless key == ""
    self.hash_data_will_change! unless key == ""
    self
  end
end