Class: SinatraHealthCheck::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra-health-check/status.rb

Overview

Application status definition

Direct Known Subclasses

Aggregated

Defined Under Namespace

Classes: Aggregated, ForgivingAggregator, OverwritingAggregator, StrictAggregator

Constant Summary collapse

SEVERITIES =
{
  :ok      => 0,
  :warning => 1,
  :error   => 2,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, message, extras = {}) ⇒ Status

Returns a new instance of Status.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/sinatra-health-check/status.rb', line 12

def initialize(level, message, 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 message
  raise ArgumentError, "extras must be a hash, but is #{extras.class}" unless extras.is_a?(Hash)

  @level = level
  @message = message
  @extras = extras
end

Instance Attribute Details

#extrasObject (readonly)

Returns the value of attribute extras.



10
11
12
# File 'lib/sinatra-health-check/status.rb', line 10

def extras
  @extras
end

#levelObject (readonly)

Returns the value of attribute level.



10
11
12
# File 'lib/sinatra-health-check/status.rb', line 10

def level
  @level
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/sinatra-health-check/status.rb', line 10

def message
  @message
end

Instance Method Details

#to_hObject



27
28
29
30
31
32
# File 'lib/sinatra-health-check/status.rb', line 27

def to_h
  {
    :status  => level.to_s.upcase,
    :message => message,
  }.merge(extras)
end

#to_iObject Also known as: severity



22
23
24
# File 'lib/sinatra-health-check/status.rb', line 22

def to_i
  SEVERITIES[level]
end

#to_jsonObject



34
35
36
# File 'lib/sinatra-health-check/status.rb', line 34

def to_json
  to_h.to_json
end