module SerialBox::ClassMethods
Methods added to the class that this module is mixed into.
Public Instance Methods
_serialbox_serializer()
click to toggle source
@private
# File lib/serialbox.rb, line 54 def _serialbox_serializer() @_serialbox_serializer end
serialize_fields() { |_serialbox_serializer| ... }
click to toggle source
Call this method to define how your object is serialized. This method yields an object on which you call methods to define your serialization.
@yield [serializer] A block where you can define how your object is
serialized.
@yieldparam [SerialBox::Serializer] serializer An object you can use to
define your serialization strategy.
# File lib/serialbox.rb, line 25 def serialize_fields @_serialbox_serializer = Serializer.new(self) yield @_serialbox_serializer end
serialize_with(*serializers)
click to toggle source
@overload serialize_with
(serializer, …)
Call this method to specify which serialization formats to use. @param [Symbol, Class] serializer A serialization format adapter or the name of such adapter under the `SerialBox::Serializers` namespace. See the classes under {SerialBox::Serializers} for a list of possible values.
# File lib/serialbox.rb, line 38 def serialize_with(*serializers) serializers.map! do |s| case s when Class s when Symbol, String SerialBox::Serializers.const_get(s.to_sym) else raise ArgumentError, "Unknown serializer #{s.inspect}" end end serializers.each { |serializer| include serializer } end