Class: SinatraHealthCheck::Status
- Inherits:
-
Object
- Object
- SinatraHealthCheck::Status
- Defined in:
- lib/sinatra-health-check/status.rb
Overview
Application status definition
Direct Known Subclasses
Defined Under Namespace
Classes: Aggregated, ForgivingAggregator, OverwritingAggregator, StrictAggregator
Constant Summary collapse
- SEVERITIES =
{ :ok => 0, :warning => 1, :error => 2, }
Instance Attribute Summary collapse
-
#extras ⇒ Object
readonly
Returns the value of attribute extras.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(level, message, extras = {}) ⇒ Status
constructor
A new instance of Status.
- #to_h ⇒ Object
- #to_i ⇒ Object (also: #severity)
- #to_json ⇒ Object
Constructor Details
#initialize(level, message, extras = {}) ⇒ Status
Returns a new instance of Status.
12 13 14 15 16 17 18 19 20 |
# File 'lib/sinatra-health-check/status.rb', line 12 def initialize(level, , extras = {}) raise ArgumentError, "level must be one of #{SEVERITIES.keys.join(', ')}, but is #{level}" unless SEVERITIES[level] raise ArgumentError, "message must not be nil" unless raise ArgumentError, "extras must be a hash, but is #{extras.class}" unless extras.is_a?(Hash) @level = level @message = @extras = extras end |
Instance Attribute Details
#extras ⇒ Object (readonly)
Returns the value of attribute extras.
10 11 12 |
# File 'lib/sinatra-health-check/status.rb', line 10 def extras @extras end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
10 11 12 |
# File 'lib/sinatra-health-check/status.rb', line 10 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/sinatra-health-check/status.rb', line 10 def @message end |
Instance Method Details
#to_h ⇒ Object
27 28 29 30 31 32 |
# File 'lib/sinatra-health-check/status.rb', line 27 def to_h { :status => level.to_s.upcase, :message => , }.merge(extras) end |
#to_i ⇒ Object Also known as: severity
22 23 24 |
# File 'lib/sinatra-health-check/status.rb', line 22 def to_i SEVERITIES[level] end |
#to_json ⇒ Object
34 35 36 |
# File 'lib/sinatra-health-check/status.rb', line 34 def to_json to_h.to_json end |