Sha256: 60964b0a3eac2f21525aba9888529d9575ddf65c509c4a9960196e7e50b6f505

Contents?: true

Size: 985 Bytes

Versions: 23

Compression:

Stored size: 985 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc
  module Fields #:nodoc:

    # This module maps classes used in field type definitions to the custom
    # definable field in Mongoid.
    module Mappings
      extend self

      MODULE = "Mongoid::Fields::Serializable"

      # 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)
        return Serializable::Object unless klass
        if foreign_key
          return "#{MODULE}::ForeignKeys::#{klass.to_s.demodulize}".constantize
        end
        begin
          "#{MODULE}::#{klass.to_s.demodulize}".constantize
        rescue NameError
          klass
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mongoid-2.2.6 lib/mongoid/fields/mappings.rb
mongoid-2.3.5 lib/mongoid/fields/mappings.rb
mongoid-2.2.5 lib/mongoid/fields/mappings.rb
mongoid-2.3.4 lib/mongoid/fields/mappings.rb
mongoid-2.2.4 lib/mongoid/fields/mappings.rb
mongoid-2.3.3 lib/mongoid/fields/mappings.rb
mongoid-2.3.2 lib/mongoid/fields/mappings.rb
mongoid-2.2.3 lib/mongoid/fields/mappings.rb
mongoid-2.3.1 lib/mongoid/fields/mappings.rb
mongoid-2.3.0 lib/mongoid/fields/mappings.rb
mongoid-2.2.2 lib/mongoid/fields/mappings.rb
mongoid-2.2.1 lib/mongoid/fields/mappings.rb
mongoid-2.2.0 lib/mongoid/fields/mappings.rb
mongoid-2.1.9 lib/mongoid/fields/mappings.rb
mongoid-2.1.8 lib/mongoid/fields/mappings.rb
mongoid-2.1.7 lib/mongoid/fields/mappings.rb
mongoid-2.1.6 lib/mongoid/fields/mappings.rb
mongoid-2.1.5 lib/mongoid/fields/mappings.rb
mongoid-2.1.4 lib/mongoid/fields/mappings.rb
mongoid-2.1.3 lib/mongoid/fields/mappings.rb