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
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/logidze/history/type.rb', line 14 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
36 37 38 |
# File 'lib/logidze/history/type.rb', line 36 def changed_in_place?(raw_old_value, new_value) cast_value(raw_old_value) != new_value end |
#serialize(value) ⇒ Object
rubocop:enable Style/RescueModifier
27 28 29 30 31 32 33 34 |
# File 'lib/logidze/history/type.rb', line 27 def serialize(value) case value when Hash, History ::ActiveSupport::JSON.encode(value) else super end end |
#type ⇒ Object
9 10 11 |
# File 'lib/logidze/history/type.rb', line 9 def type :jsonb end |