Class: 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).
Constant Summary
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary
Attributes inherited from Method
#block, #documentation, #node, #return_type, #signature_help, #signatures, #visibility
Attributes inherited from Callable
#block, #parameters, #return_type
Attributes inherited from Closure
Attributes inherited from Base
#code_object, #combine_priority, #directives, #docstring, #name, #path, #return_type, #source
Attributes included from Common
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
Methods inherited from Method
#==, #all_rooted?, #anon_splat?, #attribute?, #block?, #combine_all_signature_pins, #combine_signatures, #combine_visibility, #combine_with, #completion_item_kind, #detail, #explicit?, #generate_signature, #method_name, #nearly?, #overloads, #path, #probe, #proxy_with_signatures, #reset_generated!, #resolve_ref_tag, #rest_of_stack, #symbol_kind, #to_rbs, #transform_types, #typify, #with_single_signature
Methods inherited from Callable
#arity, #arity_matches?, #block?, #blockless_parameters, #choose_parameters, #combine_blocks, #combine_with, #generics, #mandatory_positional_param_count, #method_name, #method_namespace, #parameter_names, #resolve_generics_from_context, #resolve_generics_from_context_until_complete, #to_rbs, #transform_types, #typify
Methods inherited from Closure
#binder, #combine_with, #context, #gates, #generic_defaults, #generics, #rbs_generics, #to_rbs
Methods inherited from Base
#==, #all_location_text, #all_rooted?, #assert_location_provided, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #choose_priority, #closure, #combine_directives, #combine_name, #combine_return_type, #combine_with, #comments, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_rbs, #to_s, #transform_types, #type_desc, #typify, #variable?
Methods included from Logging
Methods included from Documenting
#documentation, normalize_indentation, strip_html_comments
Methods included from Conversions
#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#binder, #closure, #comments, #name, #namespace, #path, #return_type, #source
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.
18 19 20 21 22 23 24 25 |
# File 'lib/solargraph/pin/delegated_method.rb', line 18 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) super(name: name, **splat) @receiver_chain = receiver @resolved_method = method @receiver_method_name = receiver_method_name end |
Instance Method Details
#inner_desc ⇒ Object
27 28 29 |
# File 'lib/solargraph/pin/delegated_method.rb', line 27 def inner_desc "#{name} => #{@receiver_chain}##{@receiver_method_name}" end |
#location ⇒ Object
31 32 33 34 35 |
# File 'lib/solargraph/pin/delegated_method.rb', line 31 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
38 39 40 41 42 |
# File 'lib/solargraph/pin/delegated_method.rb', line 38 def type_location return super if super @resolved_method&.send(:type_location) end |