Module: SerialBox::ClassMethods
- Defined in:
- lib/serialbox.rb
Overview
Methods added to the class that this module is mixed into.
Instance Method Summary collapse
- #_serialbox_serializer ⇒ Object
-
#serialize_fields {|serializer| ... } ⇒ Object
Call this method to define how your object is serialized.
-
#serialize_with(serializer, ...) ⇒ Object
Call this method to specify which serialization formats to use.
Instance Method Details
#_serialbox_serializer ⇒ Object
54 |
# File 'lib/serialbox.rb', line 54 def _serialbox_serializer() @_serialbox_serializer end |
#serialize_fields {|serializer| ... } ⇒ Object
Call this method to define how your object is serialized. This method yields an object on which you call methods to define your serialization.
25 26 27 28 |
# File 'lib/serialbox.rb', line 25 def serialize_fields @_serialbox_serializer = Serializer.new(self) yield @_serialbox_serializer end |
#serialize_with(serializer, ...) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |