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`.
|
2015-01-07 16:57:45 -05:00
|
|
|
def where_object_changes_condition(arel_field, field, value)
|
|
|
|
# Need to check first (before) and secondary (after) fields
|
2017-03-31 22:26:41 -04:00
|
|
|
m1 = "%\n#{field}:\n- #{value}\n%"
|
|
|
|
m2 = "%\n#{field}:\n-%\n- #{value}\n%"
|
2016-03-05 17:39:00 -05:00
|
|
|
arel_field.matches(m1).or(arel_field.matches(m2))
|
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
|