Sha256: 32cdaad0bd4695010ab4fea25a8fe76803b3e0afe30e82417813d075eae93d98

Contents?: true

Size: 738 Bytes

Versions: 7

Compression:

Stored size: 738 Bytes

Contents

module Mongoid #:nodoc:
  module Associations #:nodoc:
    class AssociationFactory #:nodoc:

      # Creates a new association, based on the type provided and 
      # passes the name and document into the newly instantiated
      # association.
      #
      # If the type is invalid a InvalidAssociationError will be thrown.
      def self.create(association_type, association_name, document)
        case association_type
          when :belongs_to then BelongsToAssociation.new(document)
          when :has_many then HasManyAssociation.new(association_name, document)
          when :has_one then HasOneAssociation.new(association_name, document)
          else raise InvalidAssociationError
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
durran-mongoid-0.2.0 lib/mongoid/associations/association_factory.rb
durran-mongoid-0.2.2 lib/mongoid/associations/association_factory.rb
durran-mongoid-0.2.3 lib/mongoid/associations/association_factory.rb
durran-mongoid-0.2.4 lib/mongoid/associations/association_factory.rb
mongoid-0.2.7 lib/mongoid/associations/association_factory.rb
mongoid-0.2.6 lib/mongoid/associations/association_factory.rb
mongoid-0.2.5 lib/mongoid/associations/association_factory.rb