Class: Legion::Extensions::Llm::Inventory::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/llm/inventory/snapshot.rb

Overview

A structurally immutable, generation-tagged read model of the registry. Lookups return the frozen record or nil and never synthesize a default. instances_by_key contains only activated instances; publication_status_by_key also contains initializing claims. A caller cannot observe a later inventory-record or generation mutation through an older snapshot; the captured CallableHandle lifecycle is the single intentional exception. See phase-1-lex-llm-additive.md section 11.3.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generation:, instances_by_key:, offerings_by_id:, lanes_by_id:, publication_status_by_key:) ⇒ Snapshot

Returns a new instance of Snapshot.



21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 21

def initialize(generation:, instances_by_key:, offerings_by_id:, lanes_by_id:, publication_status_by_key:)
  @generation = generation
  @instances_by_key = order_instances(instances_by_key).freeze
  @offerings_by_id = offerings_by_id.dup.freeze
  @lanes_by_id = lanes_by_id.dup.freeze
  @publication_status_by_key = order_instances(publication_status_by_key).freeze
  @ordered_offerings = @offerings_by_id.keys.sort.map { |id| @offerings_by_id[id] }.freeze
  @ordered_lanes = @lanes_by_id.keys.sort.map { |id| @lanes_by_id[id] }.freeze
  freeze
end

Instance Attribute Details

#generationObject (readonly)

Returns the value of attribute generation.



19
20
21
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 19

def generation
  @generation
end

Instance Method Details

#each_instance(&block) ⇒ Object



68
69
70
71
72
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 68

def each_instance(&block)
  return to_enum(:each_instance) unless block

  @instances_by_key.each_value(&block)
end

#each_lane(&block) ⇒ Object



56
57
58
59
60
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 56

def each_lane(&block)
  return to_enum(:each_lane) unless block

  @ordered_lanes.each(&block)
end

#each_offering(&block) ⇒ Object



62
63
64
65
66
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 62

def each_offering(&block)
  return to_enum(:each_offering) unless block

  @ordered_offerings.each(&block)
end

#each_publication_status(&block) ⇒ Object



74
75
76
77
78
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 74

def each_publication_status(&block)
  return to_enum(:each_publication_status) unless block

  @publication_status_by_key.each_value(&block)
end

#instance(instance_key:) ⇒ Object



32
33
34
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 32

def instance(instance_key:)
  @instances_by_key[instance_key]
end

#lane(lane_id:) ⇒ Object



40
41
42
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 40

def lane(lane_id:)
  @lanes_by_id[lane_id]
end

#lanes_for(instance_key:) ⇒ Object



44
45
46
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 44

def lanes_for(instance_key:)
  @ordered_lanes.select { |lane| lane.instance_key == instance_key }.freeze
end

#offering(offering_id:) ⇒ Object



36
37
38
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 36

def offering(offering_id:)
  @offerings_by_id[offering_id]
end

#offerings_for(instance_key:) ⇒ Object



48
49
50
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 48

def offerings_for(instance_key:)
  @ordered_offerings.select { |offering| offering.instance_key == instance_key }.freeze
end

#publication_status(instance_key:) ⇒ Object



52
53
54
# File 'lib/legion/extensions/llm/inventory/snapshot.rb', line 52

def publication_status(instance_key:)
  @publication_status_by_key[instance_key]
end