Module: PaperTrail::Serializers::YAML
Overview
The default serializer for, e.g. ‘versions.object`.
Instance Method Summary collapse
-
#dump(object) ⇒ Object
‘recordable_object` `object` will be a plain `Hash`.
- #load(string) ⇒ Object
-
#where_object_condition(arel_field, field, value) ⇒ Object
Returns a SQL LIKE condition to be used to match the given field and value in the serialized object.
Instance Method Details
#dump(object) ⇒ Object
‘recordable_object` `object` will be a plain `Hash`. However, due to recent [memory optimizations](github.com/paper-trail-gem/paper_trail/pull/1189), when coming from `recordable_object_changes`, it will be a `HashWithIndifferentAccess`.
29 30 31 32 |
# File 'lib/paper_trail/serializers/yaml.rb', line 29 def dump(object) object = object.to_hash if object.is_a?(HashWithIndifferentAccess) ::YAML.dump object end |
#load(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/paper_trail/serializers/yaml.rb', line 11 def load(string) if use_safe_load? ::YAML.safe_load( string, permitted_classes: yaml_column_permitted_classes, aliases: true ) elsif ::YAML.respond_to?(:unsafe_load) ::YAML.unsafe_load(string) else ::YAML.load(string) end end |
#where_object_condition(arel_field, field, value) ⇒ Object
Returns a SQL LIKE condition to be used to match the given field and value in the serialized object.
36 37 38 |
# File 'lib/paper_trail/serializers/yaml.rb', line 36 def where_object_condition(arel_field, field, value) arel_field.matches("%\n#{field}: #{value}\n%") end |