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)

Returns true if the method has beeen wrapped for the given purpose, whether or not that wrapper applies to subclassed methods.

Returns:

  • (Boolean)

    Returns true if the method has beeen wrapped for the given purpose, whether or not that wrapper applies to subclassed methods.



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)

Returns The index of the target module in its ancestry array.

Returns:

  • (Integer)

    The index of the target module in its ancestry array



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)

Returns All ProxyModules prepended to the target module.

Returns:



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)

Returns Either an already-defined proxy module for the given purpose, or a new proxy module if one does not exist for the given purpose.

Returns:

  • (AroundTheWorld::ProxyModule)

    Either an already-defined proxy module for the given purpose, or a new proxy module if one does not exist for the given purpose.



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