Class: ActiveRecord::Store::HashAccessor

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/store.rb

Class Method Summary collapse

Class Method Details

.prepare(object, attribute) ⇒ Object



149
150
151
# File 'activerecord/lib/active_record/store.rb', line 149

def self.prepare(object, attribute)
  object.public_send :"#{attribute}=", {} unless object.send(attribute)
end

.read(object, attribute, key) ⇒ Object



136
137
138
139
# File 'activerecord/lib/active_record/store.rb', line 136

def self.read(object, attribute, key)
  prepare(object, attribute)
  object.public_send(attribute)[key]
end

.write(object, attribute, key, value) ⇒ Object



141
142
143
144
145
146
147
# File 'activerecord/lib/active_record/store.rb', line 141

def self.write(object, attribute, key, value)
  prepare(object, attribute)
  if value != read(object, attribute, key)
    object.public_send :"#{attribute}_will_change!"
    object.public_send(attribute)[key] = value
  end
end