module BSON::Registry
def define_type_reader(type)
def define_type_reader(type) type.module_eval <<-MOD def bson_type; BSON_TYPE; end MOD end
def get(byte, field = nil)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(Class)
- The corresponding Ruby class for the type.
Other tags:
- Example: Get the type for the byte. -
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
def handle_unsupported_type!(byte, field)
def handle_unsupported_type!(byte, field) message = "Detected unknown BSON type #{byte.inspect} " message += (field ? "for fieldname \"#{field}\". " : "in array. ") message +="Are you using the latest BSON version?" raise Error::UnsupportedType.new(message) end
def register(byte, type)
- Since: - 2.0.0
Returns:
-
(Class)
- The class.
Parameters:
-
type
(Class
) -- The class the byte maps to. -
byte
(String
) -- The single byte.
Other tags:
- Example: Register the type. -
def register(byte, type) MAPPINGS[byte.ord] = type define_type_reader(type) end