Class: Rigor::SigGen::ObservedCall

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

Overview

Per-call-site argument observation produced by ObservationCollector. ADR-14 follow-up: the earlier MVP shape (‘Array` of positional types only) could not represent keyword arguments — every call like `MethodCatalog.new(path: …, mutating_selectors: …)` discarded the whole observation via `non_positional?`. The new shape carries positional and keyword arg types in parallel so the per-position / per-keyword unions can each be reconstructed independently.

The carrier is intentionally minimal:

  • ‘positional` — frozen Array of `Rigor::Type` per positional argument, in call-site order.

  • ‘keyword` — frozen Hash mapping each keyword argument’s Symbol name to its ‘Rigor::Type`.

Generator-side callers also accept a legacy shape (plain Array of types) for backward compatibility with specs that constructed observations directly before this carrier existed; ‘ObservedCall.from(…)` does the lift.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(positional: [], keyword: {}) ⇒ ObservedCall

Returns a new instance of ObservedCall.



29
30
31
32
33
# File 'lib/rigor/sig_gen/observed_call.rb', line 29

def initialize(positional: [], keyword: {})
  @positional = positional.freeze
  @keyword = keyword.freeze
  freeze
end

Instance Attribute Details

#keywordObject (readonly)

Returns the value of attribute keyword.



27
28
29
# File 'lib/rigor/sig_gen/observed_call.rb', line 27

def keyword
  @keyword
end

#positionalObject (readonly)

Returns the value of attribute positional.



27
28
29
# File 'lib/rigor/sig_gen/observed_call.rb', line 27

def positional
  @positional
end

Class Method Details

.from(value) ⇒ Object

Lifts the legacy plain-Array shape into an ‘ObservedCall` carrier. Already-lifted values pass through unchanged. Used by `Generator#initialize`’s observations-normalisation pass so spec fixtures written against the slice-3 surface keep working.



53
54
55
56
57
58
59
# File 'lib/rigor/sig_gen/observed_call.rb', line 53

def self.from(value)
  case value
  when ObservedCall then value
  when Array then new(positional: value)
  else raise ArgumentError, "expected Array or ObservedCall, got #{value.class}"
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



39
40
41
# File 'lib/rigor/sig_gen/observed_call.rb', line 39

def ==(other)
  other.is_a?(ObservedCall) && positional == other.positional && keyword == other.keyword
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rigor/sig_gen/observed_call.rb', line 35

def empty?
  positional.empty? && keyword.empty?
end

#hashObject



44
45
46
# File 'lib/rigor/sig_gen/observed_call.rb', line 44

def hash
  [ObservedCall, positional, keyword].hash
end