Module: Mongoid::Fields::Mappings
Overview
This module maps classes used in field type definitions to the custom definable field in Mongoid.
Constant Summary collapse
- MODULE =
"Mongoid::Fields::Serializable"
Instance Method Summary collapse
-
#for(klass, foreign_key = false) ⇒ Class
Get the custom field type for the provided class used in the field definition.
Instance Method Details
#for(klass, foreign_key = false) ⇒ Class
Get the custom field type for the provided class used in the field definition.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongoid/fields/mappings.rb', line 23 def for(klass, foreign_key = false) return Serializable::Object unless klass if foreign_key return "#{MODULE}::ForeignKeys::#{klass.to_s.demodulize}".constantize end begin modules = "#{ MODULE }::|BSON::|ActiveSupport::" if match = klass.to_s.match(Regexp.new("^(#{ modules })?(\\w+)$")) "#{MODULE}::#{ match[2] }".constantize else klass.to_s.constantize end rescue NameError klass end end |