Module: ActiveRecord::Store::ClassMethods

Defined in:
activerecord/lib/active_record/store.rb

Instance Method Summary collapse

Instance Method Details

#store(store_attribute, options = {}) ⇒ Object



31
32
33
34
# File 'activerecord/lib/active_record/store.rb', line 31

def store(store_attribute, options = {})
  serialize store_attribute, Hash
  store_accessor(store_attribute, options[:accessors]) if options.has_key? :accessors
end

#store_accessor(store_attribute, *keys) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'activerecord/lib/active_record/store.rb', line 36

def store_accessor(store_attribute, *keys)
  Array(keys).flatten.each do |key|
    define_method("#{key}=") do |value|
      send(store_attribute)[key] = value
      send("#{store_attribute}_will_change!")
    end
    
    define_method(key) do
      send(store_attribute)[key]
    end
  end
end