Module: BSON::Registry

Extended by:
Registry
Included in:
Registry
Defined in:
lib/bson/registry.rb

Overview

Provides constant values for each to the BSON types and mappings from raw bytes back to these types.

See Also:

Since:

  • 2.0.0

Constant Summary collapse

MAPPINGS =

A Mapping of all the BSON types to their corresponding Ruby classes.

Since:

  • 2.0.0

{}

Instance Method Summary collapse

Instance Method Details

#get(byte) ⇒ Class

Get the class for the single byte identifier for the type in the BSON specification.

Examples:

Get the type for the byte.

BSON::Registry.get("\x01")

Returns:

  • (Class)

    The corresponding Ruby class for the type.

See Also:

Since:

  • 2.0.0



42
43
44
# File 'lib/bson/registry.rb', line 42

def get(byte)
  MAPPINGS.fetch(byte)
end

#register(byte, type) ⇒ Class

Register the Ruby type for the corresponding single byte.

Examples:

Register the type.

BSON::Registry.register("\x01", Float)

Parameters:

  • byte (String)

    The single byte.

  • The (Class)

    class the byte maps to.

Returns:

  • (Class)

    The class.

Since:

  • 2.0.0



57
58
59
60
# File 'lib/bson/registry.rb', line 57

def register(byte, type)
  MAPPINGS.store(byte, type)
  define_type_reader(type)
end