Class: Rigor::Inference::ProjectPatchedMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/inference/project_patched_methods.rb

Overview

ADR-17 § “Inference contract” — project-wide patched-method registry populated by the pre-eval pre-pass (slice 2) from the user’s ‘.rigor.yml` `pre_eval:` list.

Each entry records one ‘def` declaration the pre-pass observed inside a class / module body. The dispatcher’s ‘try_project_patched_method` tier consults this registry between the plugin tier and the dependency-source tier so project-side `lib/core_ext/string_extensions.rb` patches are visible to cross-file dispatch.

The dispatcher answers ‘Dynamic` (with a heuristic static facet) when `Entry#return_type` is non-nil, or `Dynamic` when the heuristic declined (`nil`). See Entry for the per-field contract.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

EMPTY =
new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: []) ⇒ ProjectPatchedMethods

Returns a new instance of ProjectPatchedMethods.

Parameters:

  • entries (Array<Entry>) (defaults to: [])

    flat list of declarations observed during the pre-pass. First-write-wins on ‘(class_name, method_name, kind)` duplicates so the `pre-eval.duplicate-declaration` diagnostic emission stays decoupled from registry behaviour.



45
46
47
48
49
50
51
# File 'lib/rigor/inference/project_patched_methods.rb', line 45

def initialize(entries: [])
  @by_key = entries.each_with_object({}) do |entry, acc|
    key = [entry.class_name, entry.method_name, entry.kind]
    acc[key] ||= entry
  end.freeze
  freeze
end

Instance Attribute Details

#by_keyObject (readonly)

Returns the value of attribute by_key.



38
39
40
# File 'lib/rigor/inference/project_patched_methods.rb', line 38

def by_key
  @by_key
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/rigor/inference/project_patched_methods.rb', line 60

def empty?
  @by_key.empty?
end

#lookup(class_name:, method_name:, kind:) ⇒ Entry?

Returns the recorded entry for the given ‘(class_name, method_name, kind)` triple, or `nil` when no pre-eval file declared it.

Returns:

  • (Entry, nil)

    the recorded entry for the given ‘(class_name, method_name, kind)` triple, or `nil` when no pre-eval file declared it.



56
57
58
# File 'lib/rigor/inference/project_patched_methods.rb', line 56

def lookup(class_name:, method_name:, kind:)
  @by_key[[class_name, method_name, kind]]
end