2017-12-11 04:05:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-05 22:07:32 +00:00
|
|
|
require "yaml"
|
2012-07-04 03:22:52 +00:00
|
|
|
|
|
|
|
module PaperTrail
|
|
|
|
module Serializers
|
2016-04-09 05:08:34 +00:00
|
|
|
# The default serializer for, e.g. `versions.object`.
|
2013-10-18 02:05:24 +00:00
|
|
|
module YAML
|
2013-01-31 19:49:25 +00:00
|
|
|
extend self # makes all instance methods become module methods as well
|
|
|
|
|
|
|
|
def load(string)
|
2013-10-18 02:05:24 +00:00
|
|
|
::YAML.load string
|
2012-07-04 03:22:52 +00:00
|
|
|
end
|
|
|
|
|
2019-03-13 17:47:23 +00:00
|
|
|
# @param object (Hash | HashWithIndifferentAccess) - Coming from
|
|
|
|
# `recordable_object` `object` will be a plain `Hash`. However, due to
|
|
|
|
# recent [memory optimizations](https://git.io/fjeYv), when coming from
|
|
|
|
# `recordable_object_changes`, it will be a `HashWithIndifferentAccess`.
|
2013-01-31 19:49:25 +00:00
|
|
|
def dump(object)
|
2019-03-13 17:47:23 +00:00
|
|
|
object = object.to_hash if object.is_a?(HashWithIndifferentAccess)
|
2013-10-18 02:05:24 +00:00
|
|
|
::YAML.dump object
|
2012-07-04 03:22:52 +00:00
|
|
|
end
|
2014-06-07 14:42:17 +00:00
|
|
|
|
2016-05-10 06:11:41 +00:00
|
|
|
# Returns a SQL LIKE condition to be used to match the given field and
|
|
|
|
# value in the serialized object.
|
2014-06-07 14:42:17 +00:00
|
|
|
def where_object_condition(arel_field, field, value)
|
|
|
|
arel_field.matches("%\n#{field}: #{value}\n%")
|
|
|
|
end
|
2015-01-07 21:57:45 +00:00
|
|
|
|
2016-05-10 06:11:41 +00:00
|
|
|
# Returns a SQL LIKE condition to be used to match the given field and
|
|
|
|
# value in the serialized `object_changes`.
|
2017-12-11 02:58:18 +00:00
|
|
|
def where_object_changes_condition(*)
|
|
|
|
raise <<-STR.squish.freeze
|
|
|
|
where_object_changes no longer supports reading YAML from a text
|
|
|
|
column. The old implementation was inaccurate, returning more records
|
|
|
|
than you wanted. This feature was deprecated in 8.1.0 and removed in
|
|
|
|
9.0.0. The json and jsonb datatypes are still supported. See
|
2018-05-09 11:25:56 +00:00
|
|
|
discussion at https://github.com/paper-trail-gem/paper_trail/pull/997
|
2017-12-11 02:58:18 +00:00
|
|
|
STR
|
2015-01-07 21:57:45 +00:00
|
|
|
end
|
2012-07-04 03:22:52 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-28 06:12:42 +00:00
|
|
|
end
|