Class: Legion::Extensions::Llm::Inventory::InstanceRecord

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

Overview

An activated exact instance's complete published state. Its lanes are keyed by the 5-tuple lane id; its availability is available or unavailable, never initializing. See section 10.6.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ InstanceRecord

Returns a new instance of InstanceRecord.



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/legion/extensions/llm/inventory/records.rb', line 454

def initialize(**kwargs)
  RecordSupport.check_unknown_kwargs!(kwargs: kwargs, members: self.class.members)
  instance_key = kwargs[:instance_key]
  callable_handle = kwargs[:callable_handle]
  availability = kwargs[:availability]
  raise Errors::ValidationError, 'instance_key must be an InstanceKey' unless instance_key.is_a?(Identity::InstanceKey)
  raise Errors::ValidationError, 'callable_handle must be a CallableHandle' unless callable_handle.is_a?(CallableHandle)
  unless availability.is_a?(AvailabilityFact) && %i[available unavailable].include?(availability.state)
    raise Errors::ValidationError, 'availability must be an available/unavailable AvailabilityFact'
  end

  super(
    instance_key: instance_key,
    callable_handle: callable_handle,
    availability: availability,
    lanes_by_id: validate_lanes!(kwargs[:lanes_by_id], instance_key, callable_handle),
    publisher_id: nonempty_id!(kwargs[:publisher_id], :publisher_id),
    publisher_token_id: nonempty_id!(kwargs[:publisher_token_id], :publisher_token_id),
    published_sequence: RecordSupport.nonnegative_integer(value: kwargs[:published_sequence], field: :published_sequence),
    published_at: require_time!(kwargs[:published_at], :published_at)
  )
end

Instance Attribute Details

#availabilityObject (readonly)

Returns the value of attribute availability

Returns:

  • (Object)

    the current value of availability



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def availability
  @availability
end

#callable_handleObject (readonly)

Returns the value of attribute callable_handle

Returns:

  • (Object)

    the current value of callable_handle



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def callable_handle
  @callable_handle
end

#instance_keyObject (readonly)

Returns the value of attribute instance_key

Returns:

  • (Object)

    the current value of instance_key



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def instance_key
  @instance_key
end

#lanes_by_idObject (readonly)

Returns the value of attribute lanes_by_id

Returns:

  • (Object)

    the current value of lanes_by_id



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def lanes_by_id
  @lanes_by_id
end

#published_atObject (readonly)

Returns the value of attribute published_at

Returns:

  • (Object)

    the current value of published_at



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def published_at
  @published_at
end

#published_sequenceObject (readonly)

Returns the value of attribute published_sequence

Returns:

  • (Object)

    the current value of published_sequence



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def published_sequence
  @published_sequence
end

#publisher_idObject (readonly)

Returns the value of attribute publisher_id

Returns:

  • (Object)

    the current value of publisher_id



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def publisher_id
  @publisher_id
end

#publisher_token_idObject (readonly)

Returns the value of attribute publisher_token_id

Returns:

  • (Object)

    the current value of publisher_token_id



450
451
452
# File 'lib/legion/extensions/llm/inventory/records.rb', line 450

def publisher_token_id
  @publisher_token_id
end

Instance Method Details

#nonempty_id!(value, field) ⇒ Object



488
489
490
491
492
# File 'lib/legion/extensions/llm/inventory/records.rb', line 488

def nonempty_id!(value, field)
  raise Errors::ValidationError, "#{field} must be a nonempty String" unless value.is_a?(::String) && !value.empty?

  value.dup.freeze
end

#require_time!(value, field) ⇒ Object



494
495
496
497
498
# File 'lib/legion/extensions/llm/inventory/records.rb', line 494

def require_time!(value, field)
  raise Errors::ValidationError, "#{field} must be a Time" unless value.is_a?(::Time)

  value.dup.freeze
end

#validate_lanes!(lanes_by_id, instance_key, callable_handle) ⇒ Object



477
478
479
480
481
482
483
484
485
486
# File 'lib/legion/extensions/llm/inventory/records.rb', line 477

def validate_lanes!(lanes_by_id, instance_key, callable_handle)
  raise Errors::ValidationError, 'lanes_by_id must be a Hash' unless lanes_by_id.is_a?(::Hash)

  lanes_by_id.each do |lane_id, lane|
    raise Errors::ValidationError, "lane #{lane_id} must be a LaneRecord" unless lane.is_a?(LaneRecord)
    raise Errors::ValidationError, "lane #{lane_id} key mismatch" unless lane.lane_id == lane_id
    raise Errors::ValidationError, "lane #{lane_id} must share the instance callable/key" unless lane.instance_key == instance_key && lane.callable_handle.equal?(callable_handle)
  end
  lanes_by_id.dup.freeze
end