Class: Logidze::History::Type
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Logidze::History::Type
- Defined in:
- lib/logidze/history/type.rb
Overview
Type for converting JSONB to and from History
Instance Method Summary collapse
-
#cast_value(value) ⇒ Object
rubocop:disable Style/RescueModifier.
- #changed_in_place?(raw_old_value, new_value) ⇒ Boolean
-
#serialize(value) ⇒ Object
rubocop:enable Style/RescueModifier.
- #type ⇒ Object
Instance Method Details
#cast_value(value) ⇒ Object
rubocop:disable Style/RescueModifier
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/logidze/history/type.rb', line 13 def cast_value(value) case value when String decoded = ::ActiveSupport::JSON.decode(value) rescue nil History.new(decoded) if decoded.present? when Hash History.new(value) when History value end end |
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
35 36 37 |
# File 'lib/logidze/history/type.rb', line 35 def changed_in_place?(raw_old_value, new_value) cast_value(raw_old_value) != new_value end |
#serialize(value) ⇒ Object
rubocop:enable Style/RescueModifier
26 27 28 29 30 31 32 33 |
# File 'lib/logidze/history/type.rb', line 26 def serialize(value) case value when Hash, History ::ActiveSupport::JSON.encode(value) else super end end |
#type ⇒ Object
8 9 10 |
# File 'lib/logidze/history/type.rb', line 8 def type :jsonb end |