Module: Mongo::Protocol::Registry

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

Overview

Provides a registry for looking up a message class based on op code.

Since:

  • 2.5.0

Constant Summary collapse

MAPPINGS =

A Mapping of all the op codes to their corresponding Ruby classes.

Since:

  • 2.5.0

{}

Instance Method Summary collapse

Instance Method Details

#get(op_code, message = nil) ⇒ Class

Get the class for the given op code and raise an error if it's not found.

Examples:

Get the type for the op code.

Mongo::Protocol::Registry.get(1)

Returns:

  • (Class)

    The corresponding Ruby class for the message type.

Since:

  • 2.5.0



38
39
40
41
42
43
44
# File 'lib/mongo/protocol/registry.rb', line 38

def get(op_code, message = nil)
  if type = MAPPINGS[op_code]
    type
  else
    handle_unsupported_op_code!(op_code)
  end
end

#register(op_code, type) ⇒ Class

Register the Ruby type for the corresponding op code.

Examples:

Register the op code.

Mongo::Protocol::Registry.register(1, Reply)

Parameters:

  • op_code (Fixnum)

    The op code.

  • type (Class)

    The class the op code maps to.

Returns:

  • (Class)

    The class.

Since:

  • 2.5.0



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

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