Module: Sequel::Plugins::Serialization::ClassMethods
- Defined in:
- lib/sequel/plugins/serialization.rb
Instance Attribute Summary collapse
-
#serialization_map ⇒ Object
readonly
A map of the serialized columns for this model.
-
#serialization_module ⇒ Object
Module to store the serialized column accessor methods, so they can call be overridden and call super to get the serialization behavior.
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
Copy the serialization format and columns to serialize into the subclass.
-
#serialization_format ⇒ Object
The first value in the serialization map.
-
#serialize_attributes(format, *columns) ⇒ Object
Create instance level reader that deserializes column values on request, and instance level writer that stores new deserialized value in deserialized columns.
-
#serialized_columns ⇒ Object
The columns that will be serialized.
Instance Attribute Details
#serialization_map ⇒ Object (readonly)
A map of the serialized columns for this model. Keys are column symbols, values are serialization formats (:marshal, :yaml, or :json).
49 50 51 |
# File 'lib/sequel/plugins/serialization.rb', line 49 def serialization_map @serialization_map end |
#serialization_module ⇒ Object
Module to store the serialized column accessor methods, so they can call be overridden and call super to get the serialization behavior
53 54 55 |
# File 'lib/sequel/plugins/serialization.rb', line 53 def serialization_module @serialization_module end |
Instance Method Details
#inherited(subclass) ⇒ Object
Copy the serialization format and columns to serialize into the subclass.
56 57 58 59 60 |
# File 'lib/sequel/plugins/serialization.rb', line 56 def inherited(subclass) super sm = serialization_map.dup subclass.instance_eval{@serialization_map = sm} end |
#serialization_format ⇒ Object
The first value in the serialization map. This is only for backwards compatibility, use serialization_map in new code.
64 65 66 |
# File 'lib/sequel/plugins/serialization.rb', line 64 def serialization_format serialization_map.values.first end |
#serialize_attributes(format, *columns) ⇒ Object
Create instance level reader that deserializes column values on request, and instance level writer that stores new deserialized value in deserialized columns
71 72 73 74 75 |
# File 'lib/sequel/plugins/serialization.rb', line 71 def serialize_attributes(format, *columns) raise(Error, "Unsupported serialization format (#{format}), should be :marshal, :yaml, or :json") unless [:marshal, :yaml, :json].include?(format) raise(Error, "No columns given. The serialization plugin requires you specify which columns to serialize") if columns.empty? define_serialized_attribute_accessor(format, *columns) end |
#serialized_columns ⇒ Object
The columns that will be serialized. This is only for backwards compatibility, use serialization_map in new code.
79 80 81 |
# File 'lib/sequel/plugins/serialization.rb', line 79 def serialized_columns serialization_map.keys end |