Class: ActiveRecord::Type::Json
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- ActiveRecord::Type::Json
show all
- Includes:
- ActiveModel::Type::Helpers::Mutable
- Defined in:
- lib/active_record/type/json.rb
Constant Summary
collapse
- JSON_ENCODER =
ActiveSupport::JSON::Encoding.json_encoder.new(escape: false)
Instance Method Summary
collapse
Instance Method Details
#accessor ⇒ Object
38
39
40
|
# File 'lib/active_record/type/json.rb', line 38
def accessor
ActiveRecord::Store::StringKeyedHashAccessor
end
|
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
34
35
36
|
# File 'lib/active_record/type/json.rb', line 34
def changed_in_place?(raw_old_value, new_value)
deserialize(raw_old_value) != new_value
end
|
#deserialize(value) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_record/type/json.rb', line 14
def deserialize(value)
return value unless value.is_a?(::String)
begin
ActiveSupport::JSON.decode(value)
rescue JSON::ParserError => e
ActiveSupport.error_reporter.report(e, source: "application.active_record")
nil
end
end
|
#serialize(value) ⇒ Object
30
31
32
|
# File 'lib/active_record/type/json.rb', line 30
def serialize(value)
JSON_ENCODER.encode(value) unless value.nil?
end
|
#type ⇒ Object
10
11
12
|
# File 'lib/active_record/type/json.rb', line 10
def type
:json
end
|