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 31A 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 67
def define_type_reader(type) type.module_eval <<-MOD 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 41
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 73
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 60
def register(op_code, type) MAPPINGS.store(op_code, type) define_type_reader(type) end