Module: BSON::Registry
Overview
Provides constant values for each to the BSON types and mappings from raw bytes back to these types.
Constant Summary collapse
- MAPPINGS =
A Mapping of all the BSON types to their corresponding Ruby classes.
{}
Instance Method Summary collapse
-
#get(byte, field = nil) ⇒ Class
Get the class for the single byte identifier for the type in the BSON specification.
-
#register(byte, type) ⇒ Class
Register the Ruby type for the corresponding single byte.
Instance Method Details
#get(byte, field = nil) ⇒ Class
Get the class for the single byte identifier for the type in the BSON specification.
44 45 46 47 48 49 50 |
# File 'lib/bson/registry.rb', line 44 def get(byte, field = nil) if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord]) type else handle_unsupported_type!(byte, field) end end |
#register(byte, type) ⇒ Class
Register the Ruby type for the corresponding single byte.
63 64 65 66 |
# File 'lib/bson/registry.rb', line 63 def register(byte, type) MAPPINGS[byte.ord] = type define_type_reader(type) end |