Class: Necropsy::AnalysisHealth

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(status:, reasons: []) ⇒ AnalysisHealth

Returns a new instance of AnalysisHealth.

Raises:

  • (ArgumentError)


884
885
886
887
888
889
# File 'lib/necropsy/models.rb', line 884

def initialize(status:, reasons: [])
  normalized_status = status.to_sym
  raise ArgumentError, "invalid analysis health status: #{status}" unless %i[complete degraded invalid].include?(normalized_status)

  super(status: normalized_status, reasons: reasons.freeze)
end

Instance Attribute Details

#reasonsObject (readonly)

Returns the value of attribute reasons

Returns:

  • (Object)

    the current value of reasons



862
863
864
# File 'lib/necropsy/models.rb', line 862

def reasons
  @reasons
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



862
863
864
# File 'lib/necropsy/models.rb', line 862

def status
  @status
end

Class Method Details

.completeObject



870
871
872
# File 'lib/necropsy/models.rb', line 870

def self.complete
  new(status: :complete, reasons: [])
end

.from_reasons(reasons) ⇒ Object



863
864
865
866
867
868
# File 'lib/necropsy/models.rb', line 863

def self.from_reasons(reasons)
  normalized = Array(reasons).map { |reason| normalize_reason(reason) }
  status = normalized.any? { |reason| reason.fetch('severity') == 'invalid' } ? :invalid : :degraded
  status = :complete if normalized.empty?
  new(status: status || :complete, reasons: normalized)
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


891
892
893
# File 'lib/necropsy/models.rb', line 891

def complete?
  status == :complete
end

#to_hObject



895
896
897
# File 'lib/necropsy/models.rb', line 895

def to_h
  { 'status' => status.to_s, 'reasons' => reasons }
end