Module: FIRM::Serializable::CoreExt

Included in:
OpenStruct
Defined in:
lib/firm/serialize/core.rb

Overview

FIRM::Serializable is not included for the Ruby core classes as the would also extend these classes with the engine specific extension that we do not need nor want here. Instead we define the (slim) mixin module CoreExt to extend the non-POD core classes. POD classes (nil, boolean, integer, float) cannot be serialized separately but only as properties of complex serializables.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/firm/serialize/core.rb', line 19

def self.included(base)
  base.class_eval do
    # Deserializes object from source data
    # @param [IO,String] source source data (String or IO(-like object))
    # @param [Symbol, String] format data format of source
    # @return [Object] deserialized object
    def self.deserialize(source, format: Serializable.default_format)
      Serializable.deserialize(source, format: format)
    end
  end
end

Instance Method Details

#serialize(io = nil, pretty: false, format: FIRM::Serializable.default_format) ⇒ Object



15
16
17
# File 'lib/firm/serialize/core.rb', line 15

def serialize(io = nil, pretty: false, format: FIRM::Serializable.default_format)
  FIRM::Serializable[format].dump(self, io, pretty: pretty)
end