Module: Mongo::Protocol::Registry
| Relationships & Source Files | |
| Defined in: | lib/mongo/protocol/registry.rb |
Overview
Provides a registry for looking up a message class based on op code.
Constant Summary
-
MAPPINGS =
# File 'lib/mongo/protocol/registry.rb', line 28
A Mapping of all the op codes to their corresponding Ruby classes.
{}
Instance Method Summary
-
#get(op_code, _message = nil) ⇒ Class
Get the class for the given op code and raise an error if it’s not found.
-
#register(op_code, type) ⇒ Class
Register the Ruby type for the corresponding op code.
- #define_type_reader(type) private
- #handle_unsupported_op_code!(op_code) private
Instance Method Details
#define_type_reader(type) (private)
# File 'lib/mongo/protocol/registry.rb', line 64
def define_type_reader(type) type.module_eval <<-MOD, __FILE__, __LINE__ + 1 def op_code; OP_CODE; end MOD end
#get(op_code, _message = nil) ⇒ Class
Get the class for the given op code and raise an error if it’s not found.
# File 'lib/mongo/protocol/registry.rb', line 38
def get(op_code, = nil) if type = MAPPINGS[op_code] type else handle_unsupported_op_code!(op_code) end end
#handle_unsupported_op_code!(op_code) (private)
# File 'lib/mongo/protocol/registry.rb', line 70
def handle_unsupported_op_code!(op_code) = "Detected unknown message type with op code: #{op_code}." raise Error::UnsupportedMessageType.new() end
#register(op_code, type) ⇒ Class
Register the Ruby type for the corresponding op code.
# File 'lib/mongo/protocol/registry.rb', line 57
def register(op_code, type) MAPPINGS.store(op_code, type) define_type_reader(type) end