Sha256: dfb32958004c81c725d88e3222fc7246545921a682f723582b76543ee9a660a3

Contents?: true

Size: 705 Bytes

Versions: 8

Compression:

Stored size: 705 Bytes

Contents

module IdentityMap

  def self.included(base)
    base.extend(ClassMethods)
    class << base
      alias_method_chain :association_instance_set, :identity_map
    end
  end

  module ClassMethods

  private

  # Set the specified association instance.
  def association_instance_set_with_identity_map(name, association)
    identity_map = Thread.current['identity_map']
    unless identity_map
      association_instance_set_without_identity_map("@#{name}", association)
    else
      association_instance_set_without_identity_map("@#{name}", identity_map.put(association))
    end
  end


  end

end

if Object.const_defined?("ActiveRecord")
  ActiveRecord::Associations.send :include, IdentityMap
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ar-simple-idmap-0.2.0 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.6 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.5 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.4 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.3 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.2 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.1 lib/identity_map/active_record/associations.rb
ar-simple-idmap-0.1.0 lib/identity_map/active_record/associations.rb