Module: AroundTheWorld::MethodWrapper::ProxyCreation

Included in:
AroundTheWorld::MethodWrapper
Defined in:
lib/around_the_world/method_wrapper/proxy_creation.rb

Instance Method Summary collapse

Instance Method Details

#already_wrapped?(method_name, target, purpose) ⇒ Boolean (private)



10
11
12
# File 'lib/around_the_world/method_wrapper/proxy_creation.rb', line 10

def already_wrapped?(method_name, target, purpose)
  existing_proxy_modules(target).any? { |mod| mod.for?(purpose) && mod.defines_proxy_method?(method_name) }
end

#base_ancestry_index(target) ⇒ Integer (private)



40
41
42
# File 'lib/around_the_world/method_wrapper/proxy_creation.rb', line 40

def base_ancestry_index(target)
  target.ancestors.index(target)
end

#existing_proxy_module_with_purpose(method_name, target, purpose) ⇒ Object (private)



21
22
23
24
25
# File 'lib/around_the_world/method_wrapper/proxy_creation.rb', line 21

def existing_proxy_module_with_purpose(method_name, target, purpose)
  existing_proxy_modules(target).reverse_each.find do |ancestor|
    ancestor.for?(purpose) && !ancestor.defines_proxy_method?(method_name)
  end
end

#existing_proxy_modules(target) ⇒ Array<AroundTheWorld::ProxyModule> (private)



28
29
30
31
32
33
34
35
36
37
# File 'lib/around_the_world/method_wrapper/proxy_creation.rb', line 28

def existing_proxy_modules(target)
  target_ancestry_index = base_ancestry_index(target)

  @existing_proxy_modules ||= {}
  @existing_proxy_modules[target] ||= target.ancestors.select.with_index do |ancestor, index|
    next if index >= target_ancestry_index

    ancestor.is_a? ProxyModule
  end
end

#proxy_module_with_purpose(method_name, target, purpose) ⇒ AroundTheWorld::ProxyModule (private)



16
17
18
19
# File 'lib/around_the_world/method_wrapper/proxy_creation.rb', line 16

def proxy_module_with_purpose(method_name, target, purpose)
  existing_proxy_module_with_purpose(method_name, target, purpose) ||
    ProxyModule.new(purpose: purpose)
end