Class: Rack::ECG::Check::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ecg/check/static.rb

Direct Known Subclasses

Error, Http

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ Static

Always returns the provided value under the name key, with the result set by status.

Examples:

Return “Hello, world!” under static

use(Rack::ECG, { checks: [[:static, { value: "Hello, world!" }]] })

Return “Paper jam in tray 2” as an error under printer_status

use(Rack::ECG, {
  checks: [
    [
      :static,
      {
        value: "Paper jam in tray 2",
        success: false, # or status: Rack::ECG::Check::Status::ERROR
        name: :printer_status,
      },
    ],
  ],
})

Parameters:

  • parameters (Hash)

    a customizable set of options

Options Hash (parameters):

  • value (Object) — default: nil

    Result value

  • status (Status::ERROR, Status::OK, nil) — default: nil

    Result status (takes precedence over success)

  • success (Boolean) — default: true

    Whether the result is successful

  • name (Symbol, #to_sym) — default: :static

    Key for the check result in the response



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rack/ecg/check/static.rb', line 31

def initialize(parameters)
  parameters ||= {}

  @name = parameters.fetch(:name, :static).to_sym
  @value = parameters.fetch(:value, nil)

  @status = if parameters.key?(:status)
    parameters[:status]
  else
    parameters.fetch(:success, true) ? Status::OK : Status::ERROR
  end
end

Instance Method Details

#resultObject



44
45
46
# File 'lib/rack/ecg/check/static.rb', line 44

def result
  Result.new(@name, @status, @value)
end