Module: Sequel::Plugins::Serialization::ClassMethods

Defined in:
lib/sequel/plugins/serialization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deserialization_mapObject (readonly)

A hash with column name symbols and callable values, with the value called to deserialize the column.



108
109
110
# File 'lib/sequel/plugins/serialization.rb', line 108

def deserialization_map
  @deserialization_map
end

#serialization_mapObject (readonly)

A hash with column name symbols and callable values, with the value called to serialize the column.



112
113
114
# File 'lib/sequel/plugins/serialization.rb', line 112

def serialization_map
  @serialization_map
end

Instance Method Details

#freezeObject

Freeze serialization metadata when freezing model class.



117
118
119
120
121
122
123
# File 'lib/sequel/plugins/serialization.rb', line 117

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.

Raises:



127
128
129
130
131
132
133
134
135
136
# File 'lib/sequel/plugins/serialization.rb', line 127

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