Module: PaperTrail::Serializers::YAML
Overview
The default serializer for, e.g. versions.object.
Instance Method Summary collapse
-
#dump(object) ⇒ Object
recordable_objectobjectwill be a plainHash. - #load(string) ⇒ Object
-
#where_object_changes_condition ⇒ Object
Returns a SQL LIKE condition to be used to match the given field and value in the serialized
object_changes. -
#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](git.io/fjeYv), when coming from recordable_object_changes, it will be a HashWithIndifferentAccess.
19 20 21 22 |
# File 'lib/mongo_trails/serializers/yaml.rb', line 19 def dump(object) object = object.to_hash if object.is_a?(HashWithIndifferentAccess) ::YAML.dump object end |
#load(string) ⇒ Object
11 12 13 |
# File 'lib/mongo_trails/serializers/yaml.rb', line 11 def load(string) ::YAML.load string end |
#where_object_changes_condition ⇒ Object
Returns a SQL LIKE condition to be used to match the given field and value in the serialized object_changes.
32 33 34 35 36 37 38 39 40 |
# File 'lib/mongo_trails/serializers/yaml.rb', line 32 def where_object_changes_condition(*) raise " where_object_changes no longer supports reading YAML from a text\n column. The old implementation was inaccurate, returning more records\n than you wanted. This feature was deprecated in 8.1.0 and removed in\n 9.0.0. The json and jsonb datatypes are still supported. See\n discussion at https://github.com/paper-trail-gem/paper_trail/pull/997\n STR\nend\n".squish.freeze |
#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.
26 27 28 |
# File 'lib/mongo_trails/serializers/yaml.rb', line 26 def where_object_condition(arel_field, field, value) arel_field.matches("%\n#{field}: #{value}\n%") end |