class Logidze::History::Type

Type for converting JSONB to and from History

Public Instance Methods

cast_value(value) click to toggle source

rubocop:disable Style/RescueModifier

# 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) click to toggle source
# 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) click to toggle source

rubocop:enable Style/RescueModifier

Calls superclass method
# 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() click to toggle source
# File lib/logidze/history/type.rb, line 9
def type
  :jsonb
end