Sha256: 28042b5e545109c4380115a64e6e78d26851c0a17da0794c91ad349f23893411

Contents?: true

Size: 883 Bytes

Versions: 5

Compression:

Stored size: 883 Bytes

Contents

module MongoMapper
  module Plugins
    module Associations
      class OneEmbeddedProxy < Proxy
        undef_method :object_id

        def build(attributes={})
          @target = klass.new(attributes)
          assign_references(@target)
          loaded
          @target
        end

        def replace(doc)
          if doc.respond_to?(:attributes)
            @target = klass.load(doc.attributes)
          else
            @target = klass.load(doc)
          end
          assign_references(@target)
          loaded
          @target
        end

        protected

          def find_target
            if @value
              klass.load(@value).tap do |child|
                assign_references(child)
              end
            end
          end

          def assign_references(doc)
            doc._parent_document = owner
          end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
pwnash-mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-0.7.6 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-0.7.4 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb