module ActiveRecord::Delegation::DelegateCache

def generate_relation_method(method)

def generate_relation_method(method)
  generated_relation_methods.generate_method(method)
end

def generated_relation_methods

def generated_relation_methods
  @generated_relation_methods ||= GeneratedRelationMethods.new.tap do |mod|
    const_set(:GeneratedRelationMethods, mod)
    private_constant :GeneratedRelationMethods
  end
end

def include_relation_methods(delegate)

def include_relation_methods(delegate)
  superclass.include_relation_methods(delegate) unless base_class?
  delegate.include generated_relation_methods
end

def inherited(child_class)

def inherited(child_class)
  child_class.initialize_relation_delegate_cache
  super
end

def initialize_relation_delegate_cache

def initialize_relation_delegate_cache
  @relation_delegate_cache = cache = {}
  Delegation.delegated_classes.each do |klass|
    delegate = Class.new(klass) {
      include ClassSpecificRelation
    }
    include_relation_methods(delegate)
    mangled_name = klass.name.gsub("::", "_")
    const_set mangled_name, delegate
    private_constant mangled_name
    cache[klass] = delegate
  end
end

def relation_delegate_class(klass)

:nodoc:
def relation_delegate_class(klass)
  @relation_delegate_cache[klass]
end