Module: Farce::Internal::ValueSerialization

Included in:
Abstract::Atom, Abstract::Counter, Abstract::Flag
Defined in:
lib/farce/integrations/bson.rb,
lib/farce/integrations/cbor.rb,
lib/farce/integrations/psych.rb,
lib/farce/integrations/msgpack.rb,
lib/farce/integrations/shared/to_json.rb,
lib/farce/integrations/active_support/value_serialization.rb

BSON Integration collapse

CBOR Integration collapse

ActiveSupport Integration collapse

JSON Integration collapse

Instance Method Details

#as_extended_json(**options) ⇒ Object

Note:

This method is only available if BSON has been loaded.

Represent the current value as Extended JSON, forwarding BSON's format options.

Parameters:

  • options (Hash) —

    Options forwarded to the value's as_extended_json.

Returns:

  • (Object) —

    The Extended JSON representation.



106
# File 'lib/farce/integrations/bson.rb', line 106

def as_extended_json(**) = value.as_extended_json(**)

#as_json(options = nil) ⇒ Object?

Note:

This methods is only available if ActiveSupport has been loaded.

Convert the current value using ActiveSupport's JSON conversion.

Returns The JSON-compatible value.

Parameters:

  • options (Hash, nil) (defaults to: nil) —

    Options forwarded to the current value's as_json.

Returns:

  • (Object, nil) —

    The JSON-compatible value.



15
# File 'lib/farce/integrations/active_support/value_serialization.rb', line 15

def as_json(...) = value.as_json(...)

#to_bson(buffer = ::BSON::ByteBuffer.new) ⇒ BSON::ByteBuffer

Note:

This method is only available if BSON has been loaded.

Serialize the current stored value using its BSON representation. Use BSON::Document.new when embedding value wrappers in ordinary Ruby hashes.

Parameters:

  • buffer (BSON::ByteBuffer) (defaults to: ::BSON::ByteBuffer.new) —

    An optional buffer to append to.

Returns:

  • (BSON::ByteBuffer) —

    The buffer containing the encoded value.



94
# File 'lib/farce/integrations/bson.rb', line 94

def to_bson(buffer = ::BSON::ByteBuffer.new) = to_bson_normalized_value.to_bson(buffer)

#to_bson_normalized_value ⇒ Object

Note:

This method is only available if BSON has been loaded.

Read the stored value once and normalize it for BSON encoding.

Returns:

  • (Object) —

    The normalized current value.



99
# File 'lib/farce/integrations/bson.rb', line 99

def to_bson_normalized_value = value.to_bson_normalized_value

#to_cbor(*arguments) ⇒ String, ...

Note:

This method is only available if CBOR has been loaded.

Note:

On CRuby, CBOR's native encoder must run in the main Ractor.

Serialize the current value using its CBOR representation.

Parameters:

  • arguments (Array<Object>) —

    Arguments forwarded to the value's to_cbor.

Returns:

  • (String, ::CBOR::Packer, nil) —

    Encoded bytes, the supplied packer, or nil when writing to IO.



49
# File 'lib/farce/integrations/cbor.rb', line 49

def to_cbor(...) = value.to_cbor(...)

#to_json(*arguments) ⇒ String

Note:

This method is only available if a supported JSON library has been loaded.

Serialize the current value as its primitive JSON equivalent.

Returns The generated JSON.

Parameters:

  • arguments (Array<Object>) —

    Arguments forwarded to the current value's to_json.

Returns:

  • (String) —

    The generated JSON.



40
# File 'lib/farce/integrations/shared/to_json.rb', line 40

def to_json(...) = value.to_json(...)

#to_msgpack(*arguments) ⇒ String, ::MessagePack::Packer

Note:

This method is only available if MessagePack has been loaded.

Serialize the current value as its primitive MessagePack equivalent.

Parameters:

  • arguments (Array<Object>) —

    Arguments forwarded to the value's to_msgpack.

Returns:

  • (String, ::MessagePack::Packer) —

    The encoded bytes or supplied packer.



43
# File 'lib/farce/integrations/msgpack.rb', line 43

def to_msgpack(...) = value.to_msgpack(...)