Class: Solargraph::Pin::DelegatedMethod

Inherits:
Pin::Method
  • Object
show all
Defined in:
lib/solargraph/pin/delegated_method.rb

Overview

A DelegatedMethod is a more complicated version of a MethodAlias that allows aliasing a method from a different closure (class/module etc).

Instance Method Summary collapse

Constructor Details

#initialize(method: nil, receiver: nil, name: method&.name, receiver_method_name: name, **splat) ⇒ DelegatedMethod

A DelegatedMethod can be constructed with either a :resolved_method pin, or a :receiver_chain. When a :receiver_chain is supplied, it will be used to dynamically resolve a receiver type within the given closure/scope, and the delegated method will then be resolved to a method pin on that type.

Parameters:

  • method (Method, nil) (defaults to: nil)

    an already resolved method pin.

  • receiver (Source::Chain, nil) (defaults to: nil)

    the source code used to resolve the receiver for this delegated method.

  • name (String, nil) (defaults to: method&.name)
  • receiver_method_name (String, nil) (defaults to: name)

    the method name that will be called on the receiver (defaults to :name).

  • splat (Hash{Symbol => Object})

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/solargraph/pin/delegated_method.rb', line 19

def initialize(method: nil, receiver: nil, name: method&.name, receiver_method_name: name, **splat)
  raise ArgumentError, 'either :method or :receiver is required' if (method && receiver) || (!method && !receiver)
  # @sg-ignore Need to add nil check here
  super(name: name, **splat)

  @receiver_chain = receiver
  @resolved_method = method
  @receiver_method_name = receiver_method_name
end

Instance Method Details

#inner_descObject



29
30
31
# File 'lib/solargraph/pin/delegated_method.rb', line 29

def inner_desc
  "#{name} => #{@receiver_chain}##{@receiver_method_name}"
end

#locationObject



33
34
35
36
37
# File 'lib/solargraph/pin/delegated_method.rb', line 33

def location
  return super if super

  @resolved_method&.send(:location)
end

#resolvable?(api_map) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/solargraph/pin/delegated_method.rb', line 62

def resolvable? api_map
  resolve_method(api_map)
  !!@resolved_method
end

#type_locationObject



39
40
41
42
43
# File 'lib/solargraph/pin/delegated_method.rb', line 39

def type_location
  return super if super

  @resolved_method&.send(:type_location)
end