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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serialization_mapObject (readonly)

A map of the serialized columns for this model. Keys are column symbols, values are serialization formats (:marshal, :yaml, or :json).


35
36
37
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 35

def serialization_map
  @serialization_map
end

#serialization_moduleObject

Module to store the serialized column accessor methods, so they can call be overridden and call super to get the serialization behavior


39
40
41
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 39

def serialization_module
  @serialization_module
end

Instance Method Details

#inherited(subclass) ⇒ Object

Copy the serialization format and columns to serialize into the subclass.


42
43
44
45
46
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 42

def inherited(subclass)
  super
  sm = serialization_map.dup
  subclass.instance_eval{@serialization_map = sm}
end

#serialization_formatObject

The first value in the serialization map. This is only for backwards compatibility, use serialization_map in new code.


50
51
52
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 50

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

Raises:


57
58
59
60
61
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 57

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_columnsObject

The columns that will be serialized. This is only for backwards compatibility, use serialization_map in new code.


65
66
67
# File 'lib/sequel/lib/sequel/plugins/serialization.rb', line 65

def serialized_columns
  serialization_map.keys
end