Module: Sequel::Plugins::Serialization::ClassMethods
- Defined in:
- lib/sequel/plugins/serialization.rb
Instance Attribute Summary collapse
-
#deserialization_map ⇒ Object
readonly
A hash with column name symbols and callable values, with the value called to deserialize the column.
-
#serialization_map ⇒ Object
readonly
A hash with column name symbols and callable values, with the value called to serialize the column.
Instance Method Summary collapse
-
#freeze ⇒ Object
Freeze serialization metadata when freezing model class.
-
#serialize_attributes(format, *columns) ⇒ Object
Create instance level reader that deserializes column values on request, and instance level writer that stores new deserialized values.
Instance Attribute Details
Instance Method Details
permalink #freeze ⇒ Object
Freeze serialization metadata when freezing model class.
118 119 120 121 122 123 124 |
# File 'lib/sequel/plugins/serialization.rb', line 118 def freeze @deserialization_map.freeze @serialization_map.freeze @serialization_module.freeze if @serialization_module super end |
permalink #serialize_attributes(format, *columns) ⇒ Object
Create instance level reader that deserializes column values on request, and instance level writer that stores new deserialized values. If format
is a symbol, it should correspond to a previously-registered format using register_format
. Otherwise, format
is expected to be a 2-element array of callables, with the first element being the serializer, used to convert the value used by the application to the value that will be stored in the database, and the second element being the deserializer, used to convert the value stored the database to the value used by the application.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/sequel/plugins/serialization.rb', line 133 def serialize_attributes(format, *columns) if format.is_a?(Symbol) unless format = Sequel.synchronize{REGISTERED_FORMATS[format]} raise(Error, "Unsupported serialization format: #{format} (valid formats: #{Sequel.synchronize{REGISTERED_FORMATS.keys}.inspect})") end end serializer, deserializer = format raise(Error, "No columns given. The serialization plugin requires you specify which columns to serialize") if columns.empty? define_serialized_attribute_accessor(serializer, deserializer, *columns) end |