Module: HstoreColumns

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::Base
Defined in:
lib/hstore-attributes/hstore_columns.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#read_hstore(key, hstore_column) ⇒ Object



7
8
9
10
# File 'lib/hstore-attributes/hstore_columns.rb', line 7

def read_hstore(key, hstore_column)
  new_value = send(hstore_column) || {}
  new_value.fetch(key.to_s, nil)
end

#write_hstore(key, value, hstore_column) ⇒ Object



12
13
14
15
16
17
# File 'lib/hstore-attributes/hstore_columns.rb', line 12

def write_hstore(key, value, hstore_column)
  new_value = send(hstore_column) || {}
  new_value.store(key.to_s, value)
  send("#{hstore_column}=", new_value)
  send("#{hstore_column}_will_change!")
end