Class: Docscribe::Types::ProviderChain
- Inherits:
-
Object
- Object
- Docscribe::Types::ProviderChain
- Defined in:
- lib/docscribe/types/provider_chain.rb
Overview
Resolve method signatures by querying a list of providers in order.
The first provider that returns a non-nil signature wins.
This lets Docscribe combine multiple external type sources behind one interface, for example:
- inline Sorbet signatures in the current file
- Sorbet RBI files
- RBS files
Instance Method Summary collapse
-
#initialize(*providers) ⇒ void
constructor
Initialize.
- #select_overload(sig, param_count, param_names) ⇒ Docscribe::Types::MethodSignature?
-
#signature_for(container:, scope:, name:, param_count: nil, param_names: []) ⇒ Docscribe::Types::MethodSignature?
Resolve a method signature from the first provider that can supply it.
Constructor Details
#initialize(*providers) ⇒ void
Initialize
21 22 23 |
# File 'lib/docscribe/types/provider_chain.rb', line 21 def initialize(*providers) @providers = providers.compact end |
Instance Method Details
#select_overload(sig, param_count, param_names) ⇒ Docscribe::Types::MethodSignature?
53 54 55 56 57 58 59 |
# File 'lib/docscribe/types/provider_chain.rb', line 53 def select_overload(sig, param_count, param_names) OverloadSelector.select( [sig, *sig.overloads], arg_count: param_count || 0, param_names: param_names ) end |
#signature_for(container:, scope:, name:, param_count: nil, param_names: []) ⇒ Docscribe::Types::MethodSignature?
Resolve a method signature from the first provider that can supply it.
When overloads are present, selects the best-matching signature.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/docscribe/types/provider_chain.rb', line 35 def signature_for(container:, scope:, name:, param_count: nil, param_names: []) @providers.each do |provider| sig = provider.signature_for(container: container, scope: scope, name: name) next unless sig return sig unless sig.overloads&.any? best = select_overload(sig, param_count, param_names) return best if best end nil end |