Attributes
| deserialization_map | [R] |
A hash with column name symbols and callable values, with the value called to deserialize the column. |
| serialization_map | [R] |
A hash with column name symbols and callable values, with the value called to serialize the column. |
Public Instance methods
Freeze serialization metadata when freezing model class.
# File lib/sequel/plugins/serialization.rb 129 def freeze 130 @deserialization_map.freeze 131 @serialization_map.freeze 132 @serialization_module.freeze if @serialization_module 133 134 super 135 end
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.
# File lib/sequel/plugins/serialization.rb 144 def serialize_attributes(format, *columns) 145 if format.is_a?(Symbol) 146 unless format = Sequel.synchronize{REGISTERED_FORMATS[format]} 147 raise(Error, "Unsupported serialization format: #{format} (valid formats: #{Sequel.synchronize{REGISTERED_FORMATS.keys}.inspect})") 148 end 149 end 150 serializer, deserializer = format 151 raise(Error, "No columns given. The serialization plugin requires you specify which columns to serialize") if columns.empty? 152 define_serialized_attribute_accessor(serializer, deserializer, *columns) 153 end