Class: CallMap::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/call_map/resolver.rb

Overview

Resolves a MethodCall to a Definition using the SourceIndex.

This handles the common Rails patterns:

  • bare call within the same class → instance method on context_owner
  • SomeService.execute → class method on SomeService
  • SomeClass.new(...).execute → instance method on SomeClass
  • self.foo → class method on context_owner

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Resolver

Returns a new instance of Resolver.

Parameters:



13
14
15
# File 'lib/call_map/resolver.rb', line 13

def initialize(index)
  @index = index
end

Instance Method Details

#resolve(call, context_owner:, context_kind: :instance_method, lexical_nesting: nil) ⇒ Definition?

Parameters:

  • call (MethodCall)

    the call to resolve

  • context_owner (String)

    the class/module the calling method belongs to

Returns:



20
21
22
23
24
25
26
27
28
# File 'lib/call_map/resolver.rb', line 20

def resolve(call, context_owner:, context_kind: :instance_method, lexical_nesting: nil)
  return nil if call.dynamic?

  if call.bare? || call.receiver == "self"
    resolve_bare(call, context_owner, context_kind)
  else
    resolve_receiver(call, context_owner, context_kind, lexical_nesting)
  end
end