Class: Rigor::SigGen::MethodCandidate

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/sig_gen/method_candidate.rb

Overview

Per-method record produced by the generator.

classification is one of the Classification constants; the remaining fields are populated only when applicable to that classification.

  • path — the source .rb file the def came from.
  • class_name — qualified receiver class name (e.g. "Foo::Bar"). nil for top-level / DSL-block defs the MVP skips.
  • method_name — the def's Symbol name.
  • kind:instance or :singleton.
  • inferred_returnRigor::Type instance (or nil when the inference pass disqualified the def).
  • declared_return_rbs — the existing RBS-declared return spelling, or nil when no RBS declares the method.
  • rbs — the rendered RBS one-liner the generator would emit (nil for skipped / equivalent rows).
  • skip_reason — one of Classification::SKIP_DIAGNOSTIC_IDS keys when classification is :skipped, else nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, class_name:, method_name:, kind:, classification:, inferred_return: nil, declared_return_rbs: nil, rbs: nil, skip_reason: nil, namespace_kinds: {}, class_shells: [], class_superclasses: {}) ⇒ MethodCandidate

rubocop:disable Metrics/ParameterLists



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rigor/sig_gen/method_candidate.rb', line 26

def initialize(path:, class_name:, method_name:, kind:, classification:, # rubocop:disable Metrics/ParameterLists
               inferred_return: nil, declared_return_rbs: nil, rbs: nil, skip_reason: nil,
               namespace_kinds: {}, class_shells: [], class_superclasses: {})
  @path = path
  @class_name = class_name
  @method_name = method_name
  @kind = kind
  @classification = classification
  @inferred_return = inferred_return
  @declared_return_rbs = declared_return_rbs
  @rbs = rbs
  @skip_reason = skip_reason
  @namespace_kinds = namespace_kinds.freeze
  @class_shells = class_shells.freeze
  # Qualified-class-name => superclass source token (e.g. `{ "Foo::Bar" => "Base" }`). Only plain-constant
  # superclasses appear; computed ones are absent. The Writer emits `class Bar < Base` for the leaf when
  # present.
  @class_superclasses = class_superclasses.freeze
  freeze
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def class_name
  @class_name
end

#class_shellsObject (readonly)

Returns the value of attribute class_shells.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def class_shells
  @class_shells
end

#class_superclassesObject (readonly)

Returns the value of attribute class_superclasses.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def class_superclasses
  @class_superclasses
end

#classificationObject (readonly)

Returns the value of attribute classification.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def classification
  @classification
end

#declared_return_rbsObject (readonly)

Returns the value of attribute declared_return_rbs.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def declared_return_rbs
  @declared_return_rbs
end

#inferred_returnObject (readonly)

Returns the value of attribute inferred_return.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def inferred_return
  @inferred_return
end

#kindObject (readonly)

Returns the value of attribute kind.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def kind
  @kind
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def method_name
  @method_name
end

#namespace_kindsObject (readonly)

Returns the value of attribute namespace_kinds.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def namespace_kinds
  @namespace_kinds
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def path
  @path
end

#rbsObject (readonly)

Returns the value of attribute rbs.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def rbs
  @rbs
end

#skip_reasonObject (readonly)

Returns the value of attribute skip_reason.



22
23
24
# File 'lib/rigor/sig_gen/method_candidate.rb', line 22

def skip_reason
  @skip_reason
end

Instance Method Details

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rigor/sig_gen/method_candidate.rb', line 47

def to_h
  {
    file: path,
    class: class_name,
    method: method_name.to_s,
    kind: kind.to_s,
    classification: classification.to_s,
    rbs: rbs,
    inferred_return: inferred_return&.erase_to_rbs,
    declared_return_rbs: declared_return_rbs,
    skip_reason: skip_reason ? Classification::SKIP_DIAGNOSTIC_IDS.fetch(skip_reason) : nil
  }.compact
end