2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
require "yaml"
|
2012-07-03 23:22:52 -04:00
|
|
|
|
|
|
|
module PaperTrail
|
|
|
|
module Serializers
|
2016-04-09 01:08:34 -04:00
|
|
|
# The default serializer for, e.g. `versions.object`.
|
2013-10-17 22:05:24 -04:00
|
|
|
module YAML
|
2013-01-31 14:49:25 -05:00
|
|
|
extend self # makes all instance methods become module methods as well
|
|
|
|
|
|
|
|
def load(string)
|
2013-10-17 22:05:24 -04:00
|
|
|
::YAML.load string
|
2012-07-03 23:22:52 -04:00
|
|
|
end
|
|
|
|
|
2013-01-31 14:49:25 -05:00
|
|
|
def dump(object)
|
2013-10-17 22:05:24 -04:00
|
|
|
::YAML.dump object
|
2012-07-03 23:22:52 -04:00
|
|
|
end
|
2014-06-07 10:42:17 -04:00
|
|
|
|
2016-05-10 02:11:41 -04:00
|
|
|
# Returns a SQL LIKE condition to be used to match the given field and
|
|
|
|
# value in the serialized object.
|
2014-06-07 10:42:17 -04:00
|
|
|
def where_object_condition(arel_field, field, value)
|
|
|
|
arel_field.matches("%\n#{field}: #{value}\n%")
|
|
|
|
end
|
2015-01-07 16:57:45 -05:00
|
|
|
|
2016-05-10 02:11:41 -04:00
|
|
|
# Returns a SQL LIKE condition to be used to match the given field and
|
|
|
|
# value in the serialized `object_changes`.
|
2017-12-10 21:58:18 -05: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 07:25:56 -04:00
|
|
|
discussion at https://github.com/paper-trail-gem/paper_trail/pull/997
|
2017-12-10 21:58:18 -05:00
|
|
|
STR
|
2015-01-07 16:57:45 -05:00
|
|
|
end
|
2012-07-03 23:22:52 -04:00
|
|
|
end
|
|
|
|
end
|
2012-12-28 01:12:42 -05:00
|
|
|
end
|