Sha256: 8fd3d1bbe8c765a8a4bf8a155b8dece35e790c53c1c29b341d98eb1900270016

Contents?: true

Size: 868 Bytes

Versions: 25

Compression:

Stored size: 868 Bytes

Contents

require 'active_support/core_ext/module/introspection'

module MongoModel
  module Associations
    module Base
      class Association
        attr_reader :definition, :instance
        delegate :name, :klass, :polymorphic?, :to => :definition
        
        def initialize(definition, instance)
          @definition, @instance = definition, instance
        end
        
        def proxy
          @proxy ||= proxy_class.new(self)
        end
        
        def replace(obj)
          proxy.target = obj
          proxy
        end
      
      protected
        def ensure_class(value)
          raise AssociationTypeMismatch, "expected instance of #{klass} but got #{value.class}" unless value.is_a?(klass)
        end
      
      private
        def proxy_class
          self.class.parent::Proxy rescue Base::Proxy
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mongomodel-0.2.20 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.19 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.18 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.17 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.16 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.15 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.14 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.13 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.12 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.11 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.10 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.9 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.8 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.7 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.6 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.5 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.4 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.3 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.2 lib/mongomodel/concerns/associations/base/association.rb
mongomodel-0.2.1 lib/mongomodel/concerns/associations/base/association.rb