Class: Necropsy::AnalysisHealth
- Inherits:
-
Data
- Object
- Data
- Necropsy::AnalysisHealth
- Defined in:
- lib/necropsy/models.rb
Instance Attribute Summary collapse
-
#reasons ⇒ Object
readonly
Returns the value of attribute reasons.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(status:, reasons: []) ⇒ AnalysisHealth
constructor
A new instance of AnalysisHealth.
- #to_h ⇒ Object
Constructor Details
#initialize(status:, reasons: []) ⇒ AnalysisHealth
Returns a new instance of AnalysisHealth.
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
#reasons ⇒ Object (readonly)
Returns the value of attribute reasons
862 863 864 |
# File 'lib/necropsy/models.rb', line 862 def reasons @reasons end |
#status ⇒ Object (readonly)
Returns the value of attribute status
862 863 864 |
# File 'lib/necropsy/models.rb', line 862 def status @status end |
Class Method Details
.complete ⇒ Object
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
891 892 893 |
# File 'lib/necropsy/models.rb', line 891 def complete? status == :complete end |
#to_h ⇒ Object
895 896 897 |
# File 'lib/necropsy/models.rb', line 895 def to_h { 'status' => status.to_s, 'reasons' => reasons } end |