Class: Docscribe::Types::ProviderChain

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(*providers) ⇒ void

Initialize

Parameters:

  • providers (Array<Docscribe::Types::_Provider>)

    ordered signature providers



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?

Parameters:

Returns:



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.

Parameters:

  • container (String)

    e.g. "MyModule::MyClass"

  • scope (Symbol)

    :instance or :class

  • name (Symbol, String)

    method name

  • param_count (Integer?) (defaults to: nil)

    number of actual arguments

  • param_names (Array<String>) (defaults to: [])

    actual parameter names

Returns:



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