Class: Necropsy::MethodLookup

Inherits:
Data
  • Object
show all
Defined in:
lib/necropsy/models.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(targets:, status:, rejected_targets: [], lookup_chain: [], reason: nil) ⇒ MethodLookup

Returns a new instance of MethodLookup.

Raises:

  • (ArgumentError)


373
374
375
376
377
378
379
380
381
382
383
# File 'lib/necropsy/models.rb', line 373

def initialize(targets:, status:, rejected_targets: [], lookup_chain: [], reason: nil)
  status = status.to_sym
  raise ArgumentError, "invalid method lookup status: #{status.inspect}" unless RESOLUTION_STATUSES.include?(status)

  targets = Array(targets).uniq(&:graph_id).sort_by(&:graph_id).freeze
  rejected_targets = Array(rejected_targets).uniq.sort_by do |target|
    [target.definition_id, target.reason, target.evidence_ids]
  end.freeze
  lookup_chain = Array(lookup_chain).map(&:to_s).freeze
  super
end

Instance Attribute Details

#lookup_chainObject (readonly)

Returns the value of attribute lookup_chain

Returns:

  • (Object)

    the current value of lookup_chain



366
367
368
# File 'lib/necropsy/models.rb', line 366

def lookup_chain
  @lookup_chain
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



366
367
368
# File 'lib/necropsy/models.rb', line 366

def reason
  @reason
end

#rejected_targetsObject (readonly)

Returns the value of attribute rejected_targets

Returns:

  • (Object)

    the current value of rejected_targets



366
367
368
# File 'lib/necropsy/models.rb', line 366

def rejected_targets
  @rejected_targets
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



366
367
368
# File 'lib/necropsy/models.rb', line 366

def status
  @status
end

#targetsObject (readonly)

Returns the value of attribute targets

Returns:

  • (Object)

    the current value of targets



366
367
368
# File 'lib/necropsy/models.rb', line 366

def targets
  @targets
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


385
386
387
# File 'lib/necropsy/models.rb', line 385

def complete?
  status == :complete
end

#partial?Boolean

Returns:

  • (Boolean)


389
390
391
# File 'lib/necropsy/models.rb', line 389

def partial?
  status == :partial
end

#to_hObject



397
398
399
400
401
402
403
404
405
# File 'lib/necropsy/models.rb', line 397

def to_h
  {
    'target_definition_ids' => targets.map(&:graph_id),
    'status' => status.to_s,
    'rejected_targets' => rejected_targets.map(&:to_h),
    'lookup_chain' => lookup_chain,
    'reason' => reason
  }
end

#unknown?Boolean

Returns:

  • (Boolean)


393
394
395
# File 'lib/necropsy/models.rb', line 393

def unknown?
  status == :unknown
end