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 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.



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/legion/extensions/llm/inventory/records.rb', line 462

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,
    offerings_by_id: validate_offerings!(kwargs[:offerings_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



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def availability
  @availability
end

#callable_handleObject (readonly)

Returns the value of attribute callable_handle

Returns:

  • (Object)

    the current value of callable_handle



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def callable_handle
  @callable_handle
end

#instance_keyObject (readonly)

Returns the value of attribute instance_key

Returns:

  • (Object)

    the current value of instance_key



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def instance_key
  @instance_key
end

#offerings_by_idObject (readonly)

Returns the value of attribute offerings_by_id

Returns:

  • (Object)

    the current value of offerings_by_id



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def offerings_by_id
  @offerings_by_id
end

#published_atObject (readonly)

Returns the value of attribute published_at

Returns:

  • (Object)

    the current value of published_at



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def published_at
  @published_at
end

#published_sequenceObject (readonly)

Returns the value of attribute published_sequence

Returns:

  • (Object)

    the current value of published_sequence



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def published_sequence
  @published_sequence
end

#publisher_idObject (readonly)

Returns the value of attribute publisher_id

Returns:

  • (Object)

    the current value of publisher_id



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

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



458
459
460
# File 'lib/legion/extensions/llm/inventory/records.rb', line 458

def publisher_token_id
  @publisher_token_id
end

Instance Method Details

#nonempty_id!(value, field) ⇒ Object



498
499
500
501
502
# File 'lib/legion/extensions/llm/inventory/records.rb', line 498

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



504
505
506
507
508
# File 'lib/legion/extensions/llm/inventory/records.rb', line 504

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

  value.dup.freeze
end

#validate_offerings!(offerings_by_id, instance_key, callable_handle) ⇒ Object



485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/legion/extensions/llm/inventory/records.rb', line 485

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

  offerings_by_id.each do |offering_id, offering|
    raise Errors::ValidationError, "offering #{offering_id} must be an OfferingRecord" unless offering.is_a?(OfferingRecord)
    raise Errors::ValidationError, "offering #{offering_id} key mismatch" unless offering.offering_id == offering_id
    unless offering.instance_key == instance_key && offering.callable_handle.equal?(callable_handle)
      raise Errors::ValidationError, "offering #{offering_id} must share the instance callable/key"
    end
  end
  offerings_by_id.dup.freeze
end