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
#deserialization_map ⇒ Object (readonly)
A hash with column name symbols and callable values, with the value called to deserialize the column.
118 119 120 |
# File 'lib/sequel/plugins/serialization.rb', line 118 def deserialization_map @deserialization_map end |
#serialization_map ⇒ Object (readonly)
A hash with column name symbols and callable values, with the value called to serialize the column.
122 123 124 |
# File 'lib/sequel/plugins/serialization.rb', line 122 def serialization_map @serialization_map end |
Instance Method Details
#freeze ⇒ Object
Freeze serialization metadata when freezing model class.
127 128 129 130 131 132 133 |
# File 'lib/sequel/plugins/serialization.rb', line 127 def freeze @deserialization_map.freeze @serialization_map.freeze @serialization_module.freeze if @serialization_module super end |
#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.
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/sequel/plugins/serialization.rb', line 142 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 |