Module: PaperTrail::Serializers::YAML
Overview
The default serializer for, e.g. versions.object.
Constant Summary collapse
- E_WHERE_OBJ_CHANGES =
" where_object_changes has a known issue. When reading YAML from a text\n column, it may return more records than expected. Instead of a warning,\n this method may raise an error in the future. Please join the discussion\n at https://github.com/airblade/paper_trail/pull/997\n".squish.freeze
Instance Method Summary collapse
- #dump(object) ⇒ Object
- #load(string) ⇒ Object
-
#where_object_changes_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_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
20 21 22 |
# File 'lib/paper_trail/serializers/yaml.rb', line 20 def dump(object) ::YAML.dump object end |
#load(string) ⇒ Object
16 17 18 |
# File 'lib/paper_trail/serializers/yaml.rb', line 16 def load(string) ::YAML.load string end |
#where_object_changes_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_changes.
32 33 34 35 36 37 38 39 |
# File 'lib/paper_trail/serializers/yaml.rb', line 32 def where_object_changes_condition(arel_field, field, value) ::ActiveSupport::Deprecation.warn(E_WHERE_OBJ_CHANGES) # Need to check first (before) and secondary (after) fields m1 = "%\n#{field}:\n- #{value}\n%" m2 = "%\n#{field}:\n-%\n- #{value}\n%" arel_field.matches(m1).or(arel_field.matches(m2)) 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.
26 27 28 |
# File 'lib/paper_trail/serializers/yaml.rb', line 26 def where_object_condition(arel_field, field, value) arel_field.matches("%\n#{field}: #{value}\n%") end |