Class: Legion::Extensions::Llm::Inventory::MutationResult

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

Overview

The outcome of a registry mutation. Expected stale results use applied: false; every other reason requires applied: true. See 10.8.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ MutationResult

Returns a new instance of MutationResult.



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/legion/extensions/llm/inventory/records.rb', line 556

def initialize(**kwargs)
  kwargs = { publication_status: nil, instance_record: nil }.merge(kwargs)
  RecordSupport.check_unknown_kwargs!(kwargs: kwargs, members: self.class.members)

  applied = kwargs[:applied]
  reason = kwargs[:reason]
  instance_key = kwargs[:instance_key]
  publication_status = kwargs[:publication_status]
  instance_record = kwargs[:instance_record]
  RecordSupport.boolean!(value: applied, field: :applied)
  raise Errors::ValidationError, 'reason must be a Taxonomies::MUTATION_REASONS value' unless Taxonomies::MUTATION_REASONS.include?(reason)

  validate_applied_reason!(applied, reason)
  raise Errors::ValidationError, 'instance_key must be an InstanceKey' unless instance_key.is_a?(Identity::InstanceKey)
  raise Errors::ValidationError, 'publication_status must be a PublicationStatus or nil' unless publication_status.nil? || publication_status.is_a?(PublicationStatus)
  raise Errors::ValidationError, 'instance_record must be an InstanceRecord or nil' unless instance_record.nil? || instance_record.is_a?(InstanceRecord)

  super(
    applied: applied,
    reason: reason,
    generation: RecordSupport.nonnegative_integer(value: kwargs[:generation], field: :generation),
    instance_key: instance_key,
    publication_status: publication_status,
    instance_record: instance_record
  )
end

Instance Attribute Details

#appliedObject (readonly)

Returns the value of attribute applied

Returns:

  • (Object)

    the current value of applied



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def applied
  @applied
end

#generationObject (readonly)

Returns the value of attribute generation

Returns:

  • (Object)

    the current value of generation



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def generation
  @generation
end

#instance_keyObject (readonly)

Returns the value of attribute instance_key

Returns:

  • (Object)

    the current value of instance_key



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def instance_key
  @instance_key
end

#instance_recordObject (readonly)

Returns the value of attribute instance_record

Returns:

  • (Object)

    the current value of instance_record



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def instance_record
  @instance_record
end

#publication_statusObject (readonly)

Returns the value of attribute publication_status

Returns:

  • (Object)

    the current value of publication_status



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def publication_status
  @publication_status
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



553
554
555
# File 'lib/legion/extensions/llm/inventory/records.rb', line 553

def reason
  @reason
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


583
584
585
# File 'lib/legion/extensions/llm/inventory/records.rb', line 583

def applied?
  applied
end

#validate_applied_reason!(applied, reason) ⇒ Object



587
588
589
590
591
592
593
594
# File 'lib/legion/extensions/llm/inventory/records.rb', line 587

def validate_applied_reason!(applied, reason)
  non_applied = %i[stale_publisher stale_probe already_removed]
  if applied
    raise Errors::ValidationError, "applied result cannot use reason #{reason}" if non_applied.include?(reason)
  elsif !non_applied.include?(reason)
    raise Errors::ValidationError, "non-applied result requires a stale/already-removed reason, got #{reason}"
  end
end