Sha256: 92b2df53a738581fc5b713b9bbea8af75c91833f4e4cf55180e1725a80c1e6a2

Contents?: true

Size: 881 Bytes

Versions: 56

Compression:

Stored size: 881 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class OneEmbeddedProxy < Proxy
        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 = proxy_owner if doc
          end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 6 rubygems

Version Path
mongo_mapper-unstable-2010.08.05 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.04 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.03 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.02 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.01 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.31 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.30 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.29 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.28 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.27 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
thorsson-mongo_mapper-0.8.2 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.26 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.23 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.21 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.20 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.19 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.18 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.16 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.15 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.14 lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb