@@ -9,10 +9,10 @@ module Fields
99 # @api private
1010 module FieldTypes
1111
12- # The default mapping of field type symbol/string aliases to classes.
12+ # The default mapping of field type symbol/string identifiers to classes.
1313 #
1414 # @api private
15- DEFAULT_ALIASES = {
15+ DEFAULT_MAPPING = {
1616 array : Array ,
1717 big_decimal : BigDecimal ,
1818 binary : BSON ::Binary ,
@@ -42,15 +42,15 @@ class << self
4242 # @example
4343 # Mongoid::FieldTypes.get(:point)
4444 #
45- # @param [ Class | Symbol | String | Class ] field_type The field
46- # type class or its string or symbol alias .
45+ # @param [ Module | Symbol | String ] field_type The field
46+ # type class or its string or symbol identifier .
4747 #
48- # @return [ Class | nil ] The underlying field type class, or nil if
48+ # @return [ Module | nil ] The underlying field type class, or nil if
4949 # string or symbol was passed and it is not mapped to any class.
5050 def get ( field_type )
5151 case field_type
52- when Class
53- type
52+ when Module
53+ field_type
5454 when Symbol , String
5555 mapping [ field_type ]
5656 else
@@ -61,21 +61,18 @@ def get(field_type)
6161 # Defines a field type mapping, for later use in field :type option.
6262 #
6363 # @example
64- # Mongoid::FieldTypes.define (:point, Point)
64+ # Mongoid::FieldTypes.define_type (:point, Point)
6565 #
66- # @param [ Symbol | String ] field_type_alias the string or symbol
67- # alias of the defined type. The alias will be accessible as a string
68- # or a symbol regardless of the type passed to this method.
66+ # @param [ Symbol | String ] field_type the identifier of the
67+ # defined type. This identifier will be accessible as either a
68+ # string or a symbol regardless of the type passed to this method.
6969 # @param [ Class ] klass the class of the defined type, which must
7070 # include mongoize, demongoize, and evolve methods.
71- def define_alias ( field_type_alias , klass )
72- unless field_type_alias . is_a? ( String ) || field_type_alias . is_a? ( Symbol )
73- raise Mongoid ::Errors ::InvalidFieldTypeAliasName . new ( field_type_alias )
71+ def define_type ( field_type , klass )
72+ unless ( field_type . is_a? ( String ) || field_type . is_a? ( Symbol ) ) && klass . is_a? ( Module )
73+ raise Mongoid ::Errors ::InvalidFieldTypeDefinition . new ( field_type , klass )
7474 end
75- unless klass . is_a? ( Class )
76- raise Mongoid ::Errors ::InvalidFieldTypeAliasValue . new ( field_type_alias , klass )
77- end
78- mapping [ field_type_alias ] = klass
75+ mapping [ field_type ] = klass
7976 end
8077
8178 delegate :delete , to : :mapping
@@ -84,7 +81,7 @@ def define_alias(field_type_alias, klass)
8481 #
8582 # @return [ ActiveSupport::HashWithIndifferentAccess<Symbol, Class> ] The memoized field mapping.
8683 def mapping
87- @mapping ||= DEFAULT_ALIASES . dup
84+ @mapping ||= DEFAULT_MAPPING . dup
8885 end
8986 end
9087 end
0 commit comments