Class: ActiveRecord::Coders::JsonHashColumn
- Inherits:
-
Object
- Object
- ActiveRecord::Coders::JsonHashColumn
- Defined in:
- lib/active_record/coders/json_hash_column.rb
Instance Attribute Summary collapse
-
#require_update ⇒ Object
Returns the value of attribute require_update.
Instance Method Summary collapse
- #dump(hash) ⇒ Object
-
#initialize(options = {}) ⇒ JsonHashColumn
constructor
A new instance of JsonHashColumn.
- #load(hash) ⇒ Object
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( = {}) @require_update = .delete(:require_update){ false } end |
Instance Attribute Details
#require_update ⇒ Object
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 |