Sha256: 658cd80eb6411e71e9675a81af565809a95aaa3c6a7f9f5fb2fd2b5692ee57ae
Contents?: true
Size: 1.08 KB
Versions: 160
Compression:
Stored size: 1.08 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc module Fields #:nodoc: module Internal #:nodoc: end # This module maps classes used in field type definitions to the custom # definable field in Mongoid. module Mappings extend self # Get the custom field type for the provided class used in the field # definition. # # @example Get the mapping for the class. # Mappings.for(BSON::ObjectId) # # @param [ Class ] klass The class to get the field type for. # # @return [ Class ] The class of the custom field. # # @since 2.1.0 def for(klass, foreign_key = false) if klass.nil? Internal::Object elsif foreign_key Internal::ForeignKeys.const_get(klass.to_s) else modules = "BSON::|ActiveSupport::" match = klass.to_s.match(Regexp.new("^(#{ modules })?(\\w+)$")) if match and Internal.const_defined?(match[2]) Internal.const_get(match[2]) else klass end end end end end end
Version data entries
160 entries across 68 versions & 3 rubygems