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.



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/legion/extensions/llm/inventory/records.rb', line 549

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



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def applied
  @applied
end

#generationObject (readonly)

Returns the value of attribute generation

Returns:

  • (Object)

    the current value of generation



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def generation
  @generation
end

#instance_keyObject (readonly)

Returns the value of attribute instance_key

Returns:

  • (Object)

    the current value of instance_key



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def instance_key
  @instance_key
end

#instance_recordObject (readonly)

Returns the value of attribute instance_record

Returns:

  • (Object)

    the current value of instance_record



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def instance_record
  @instance_record
end

#publication_statusObject (readonly)

Returns the value of attribute publication_status

Returns:

  • (Object)

    the current value of publication_status



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def publication_status
  @publication_status
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



546
547
548
# File 'lib/legion/extensions/llm/inventory/records.rb', line 546

def reason
  @reason
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


576
577
578
# File 'lib/legion/extensions/llm/inventory/records.rb', line 576

def applied?
  applied
end

#validate_applied_reason!(applied, reason) ⇒ Object



580
581
582
583
584
585
586
587
# File 'lib/legion/extensions/llm/inventory/records.rb', line 580

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