@@ -9,10 +9,10 @@ module Fields
9
9
# @api private
10
10
module FieldTypes
11
11
12
- # The default mapping of field type symbol/string aliases to classes.
12
+ # The default mapping of field type symbol/string identifiers to classes.
13
13
#
14
14
# @api private
15
- DEFAULT_ALIASES = {
15
+ DEFAULT_MAPPING = {
16
16
array : Array ,
17
17
big_decimal : BigDecimal ,
18
18
binary : BSON ::Binary ,
@@ -42,15 +42,15 @@ class << self
42
42
# @example
43
43
# Mongoid::FieldTypes.get(:point)
44
44
#
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 .
47
47
#
48
- # @return [ Class | nil ] The underlying field type class, or nil if
48
+ # @return [ Module | nil ] The underlying field type class, or nil if
49
49
# string or symbol was passed and it is not mapped to any class.
50
50
def get ( field_type )
51
51
case field_type
52
- when Class
53
- type
52
+ when Module
53
+ field_type
54
54
when Symbol , String
55
55
mapping [ field_type ]
56
56
else
@@ -61,21 +61,18 @@ def get(field_type)
61
61
# Defines a field type mapping, for later use in field :type option.
62
62
#
63
63
# @example
64
- # Mongoid::FieldTypes.define (:point, Point)
64
+ # Mongoid::FieldTypes.define_type (:point, Point)
65
65
#
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.
69
69
# @param [ Class ] klass the class of the defined type, which must
70
70
# 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 )
74
74
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
79
76
end
80
77
81
78
delegate :delete , to : :mapping
@@ -84,7 +81,7 @@ def define_alias(field_type_alias, klass)
84
81
#
85
82
# @return [ ActiveSupport::HashWithIndifferentAccess<Symbol, Class> ] The memoized field mapping.
86
83
def mapping
87
- @mapping ||= DEFAULT_ALIASES . dup
84
+ @mapping ||= DEFAULT_MAPPING . dup
88
85
end
89
86
end
90
87
end
0 commit comments