Sha256: e47c65e84d5f2e68c1caffbe5732a2aab70fe5e7f3dbd06c811989a4b3f1edcf

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

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

      # 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(association_name, document)
        klass = association_name.to_s.titleize.constantize
        attributes = document.attributes[association_name]
        @document = klass.new(attributes)
        @document.parent = document
      end

      # All calls to this association will be delegated straight
      # to the encapsulated document.
      def method_missing(method, *args)
        @document.send(method, *args)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
durran-mongoid-0.2.0 lib/mongoid/associations/has_one_association.rb
durran-mongoid-0.2.2 lib/mongoid/associations/has_one_association.rb
durran-mongoid-0.2.3 lib/mongoid/associations/has_one_association.rb