Sha256: 8365ab4a46dd0d104049f3e2f64d2e497068c0af217033864070e07c260f68a8

Contents?: true

Size: 881 Bytes

Versions: 8

Compression:

Stored size: 881 Bytes

Contents

module Mongoid #:nodoc:
  module Associations #:nodoc:
    class HasOneAssociation #:nodoc:
      include Decorator

      delegate :valid?, :to => :document

      # Creates the new association by finding the attributes in 
      # the parent document with its name, and instantiating a 
      # new document for it.
      #
      # All method calls on this object will then be delegated
      # to the internal document itself.
      def initialize(name, document, options = {})
        class_name = options[:class_name]
        klass = class_name ? class_name.constantize : name.to_s.camelize.constantize
        attributes = document.attributes[name]
        @document = klass.new(attributes)
        @document.parent = document
        decorate!
      end

      # Equality delegates to the document.
      def ==(other)
        @document == other
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-0.6.2 lib/mongoid/associations/has_one_association.rb
mongoid-0.6.1 lib/mongoid/associations/has_one_association.rb
mongoid-0.6.0 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.11 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.10 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.9 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.8 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.7 lib/mongoid/associations/has_one_association.rb