Module: FIRM::Serializable::SerializeInstanceMethods

Includes:
JSON::SerializeInstanceMethods, XML::SerializeInstanceMethods
Defined in:
lib/firm/serializable.rb,
lib/firm/serializer/xml.rb,
lib/firm/serializer/json.rb,
lib/firm/serializer/yaml.rb

Overview

extend instance serialization methods

Instance Method Summary collapse

Methods included from JSON::SerializeInstanceMethods

#as_json

Methods included from XML::SerializeInstanceMethods

#to_xml

Instance Method Details

#disable_serializevoid

This method returns an undefined value.

Disables serialization for this object as a single property or as part of a property container (array or set).



554
555
556
557
# File 'lib/firm/serializable.rb', line 554

def disable_serialize
  # by default unset (nil) so serializing enabled
  @serialize_disabled = true
end

#encode_with(coder) ⇒ Object



114
115
116
# File 'lib/firm/serializer/yaml.rb', line 114

def encode_with(coder)
  for_serialize(coder)
end

#init_with(coder) ⇒ Object



118
119
120
121
# File 'lib/firm/serializer/yaml.rb', line 118

def init_with(coder)
  from_serialized(coder.map)
  finalize_from_serialized
end

#serialize(pretty: false, format: Serializable.default_format) ⇒ String #serialize(io, pretty: false, format: Serializable.default_format) ⇒ IO

Serialize this object

Overloads:

  • #serialize(pretty: false, format: Serializable.default_format) ⇒ String

    Returns serialized data.

    Parameters:

    • pretty (Boolean) (defaults to: false)

      if true specifies to generate pretty formatted output if possible

    • format (Symbol, String) (defaults to: Serializable.default_format)

      specifies output format

    Returns:

    • (String)

      serialized data

  • #serialize(io, pretty: false, format: Serializable.default_format) ⇒ IO

    Parameters:

    • io (IO)

      output stream to write serialized data to

    • pretty (Boolean) (defaults to: false)

      if true specifies to generate pretty formatted output if possible

    • format (Symbol, String) (defaults to: Serializable.default_format)

      specifies output format

    Returns:

    • (IO)


539
540
541
# File 'lib/firm/serializable.rb', line 539

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

#serialize_disabled?true, false

Returns true if regular serialization for this object has been disabled, false otherwise (default). Disabled serialization can be overridden for single objects (not objects maintained in property containers like arrays and sets).

Returns:

  • (true, false)


547
548
549
# File 'lib/firm/serializable.rb', line 547

def serialize_disabled?
  !!@serialize_disabled # true for any value but false
end