Class: ActiveRecord::Coders::JsonHashColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/coders/json_hash_column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ JsonHashColumn

Returns a new instance of JsonHashColumn.



7
8
9
# File 'lib/active_record/coders/json_hash_column.rb', line 7

def initialize(options = {})
  @require_update = options.delete(:require_update){ false }
end

Instance Attribute Details

#require_updateObject

Returns the value of attribute require_update.



5
6
7
# File 'lib/active_record/coders/json_hash_column.rb', line 5

def require_update
  @require_update
end

Instance Method Details

#dump(hash) ⇒ Object



11
12
13
# File 'lib/active_record/coders/json_hash_column.rb', line 11

def dump(hash)
  ::JSON.dump(hash || {})
end

#load(hash) ⇒ Object



15
16
17
# File 'lib/active_record/coders/json_hash_column.rb', line 15

def load(hash)
  ::HashWithIndifferentAccess.new ::JSON.load(hash || "{}")
end