Class: Solargraph::Pin::DelegatedMethod
- Inherits:
-
Pin::Method
- Object
- Pin::Method
- Solargraph::Pin::DelegatedMethod
- 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
-
#initialize(method: nil, receiver: nil, name: method&.name, receiver_method_name: name, **splat) ⇒ DelegatedMethod
constructor
A DelegatedMethod can be constructed with either a :resolved_method pin, or a :receiver_chain.
- #inner_desc ⇒ Object
- #location ⇒ Object
- #resolvable?(api_map) ⇒ Boolean
- #type_location ⇒ Object
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.
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_desc ⇒ Object
29 30 31 |
# File 'lib/solargraph/pin/delegated_method.rb', line 29 def inner_desc "#{name} => #{@receiver_chain}##{@receiver_method_name}" end |
#location ⇒ Object
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
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_location ⇒ Object
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 |