Sha256: e0cb4e956ad7645da5e5adfa02b2a3e330b6c0d9347a60ef0000007c1075fd90

Contents?: true

Size: 881 Bytes

Versions: 2

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.titleize.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

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-0.5.6 lib/mongoid/associations/has_one_association.rb
mongoid-0.5.5 lib/mongoid/associations/has_one_association.rb