Class: ValueObjects::ActiveRecord::JsonCoder

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

Constant Summary collapse

EMPTY_ARRAY =
[].freeze

Instance Method Summary collapse

Constructor Details

#initialize(value_class) ⇒ JsonCoder

Returns a new instance of JsonCoder.



40
41
42
# File 'lib/value_objects/active_record.rb', line 40

def initialize(value_class)
  @value_class = value_class
end

Instance Method Details

#dump(value) ⇒ Object



48
49
50
# File 'lib/value_objects/active_record.rb', line 48

def dump(value)
  value.to_json if value
end

#load(value) ⇒ Object



44
45
46
# File 'lib/value_objects/active_record.rb', line 44

def load(value)
  @value_class.load(JSON.load(value) || EMPTY_ARRAY) if value
end