Class: Necropsy::Root

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason:, definition_id: nil, node_id: nil, domain: nil, evidence: nil) ⇒ Root

Returns a new instance of Root.

Raises:

  • (ArgumentError)


543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/necropsy/models.rb', line 543

def initialize(reason:, definition_id: nil, node_id: nil, domain: nil, evidence: nil)
  definition_id ||= node_id
  definition_id = ModelNormalization.identifier(definition_id, 'definition_id')
  reason = ModelNormalization.identifier(reason, 'reason').to_sym
  domain ||= reason == :test_suite ? :test : :runtime
  domain = domain.to_sym if domain.respond_to?(:to_sym)
  raise ArgumentError, "invalid root domain: #{domain.inspect}" unless ROOT_DOMAINS.include?(domain)

  evidence ||= { 'type' => 'entry_point', 'reason' => reason.to_s }
  evidence = evidence.to_h if evidence.respond_to?(:to_h)
  raise ArgumentError, 'root evidence must be a Hash' unless evidence.is_a?(Hash)

  super(definition_id: definition_id, domain: domain, reason: reason, evidence: evidence.freeze)
end

Instance Attribute Details

#definition_idObject (readonly) Also known as: node_id

Returns the value of attribute definition_id

Returns:

  • (Object)

    the current value of definition_id



529
530
531
# File 'lib/necropsy/models.rb', line 529

def definition_id
  @definition_id
end

#domainObject (readonly)

Returns the value of attribute domain

Returns:

  • (Object)

    the current value of domain



529
530
531
# File 'lib/necropsy/models.rb', line 529

def domain
  @domain
end

#evidenceObject (readonly)

Returns the value of attribute evidence

Returns:

  • (Object)

    the current value of evidence



529
530
531
# File 'lib/necropsy/models.rb', line 529

def evidence
  @evidence
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



529
530
531
# File 'lib/necropsy/models.rb', line 529

def reason
  @reason
end

Class Method Details

.data_newObject



531
# File 'lib/necropsy/models.rb', line 531

alias_method :data_new, :new

.new(*values, **attributes) ⇒ Object Also known as: []



533
534
535
536
537
# File 'lib/necropsy/models.rb', line 533

def new(*values, **attributes)
  return data_new(node_id: values[0], reason: values[1]) if values.length == 2 && attributes.empty?

  data_new(*values, **attributes)
end

Instance Method Details

#external?Boolean

Returns:

  • (Boolean)


568
569
570
# File 'lib/necropsy/models.rb', line 568

def external?
  domain == :external
end

#runtime?Boolean

Returns:

  • (Boolean)


564
565
566
# File 'lib/necropsy/models.rb', line 564

def runtime?
  domain == :runtime
end

#test?Boolean

Returns:

  • (Boolean)


560
561
562
# File 'lib/necropsy/models.rb', line 560

def test?
  domain == :test
end

#to_hObject



572
573
574
575
576
577
578
579
580
# File 'lib/necropsy/models.rb', line 572

def to_h
  {
    'node_id' => node_id,
    'definition_id' => definition_id,
    'domain' => domain.to_s,
    'reason' => reason.to_s,
    'evidence' => evidence
  }
end