Class: Rack::ECG::Check::SequelConnection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ SequelConnection

Checks whether Sequel can connect to the database identified by the connection option.

Parameters:

  • parameters (Hash) (defaults to: {})

    a customizable set of options

Options Hash (parameters):

  • connection (String, Hash)

    Sequel connection parameters to check

  • name (String, nil)

    Name to distinguish multiple Sequel checks



14
15
16
17
# File 'lib/rack/ecg/check/sequel_connection.rb', line 14

def initialize(parameters = {})
  @connection_parameters = parameters[:connection]
  @name = parameters[:name]
end

Instance Attribute Details

#connection_parametersObject (readonly)

Returns the value of attribute connection_parameters.



7
8
9
# File 'lib/rack/ecg/check/sequel_connection.rb', line 7

def connection_parameters
  @connection_parameters
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rack/ecg/check/sequel_connection.rb', line 7

def name
  @name
end

Instance Method Details

#resultObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rack/ecg/check/sequel_connection.rb', line 19

def result
  value = ""
  status = Status::OK
  begin
    if connection_parameters.nil?
      status = Status::ERROR
      value = "Sequel Connection parameters not found"
    elsif defined?(::Sequel)
      ::Sequel.connect(connection_parameters) do |db|
        value = db.test_connection
        status = Status::OK
      end
    else
      status = Status::ERROR
      value = "Sequel not found"
    end
  rescue => e
    status = Status::ERROR
    value = e.message
  end

  Result.new(result_key.to_sym, status, value.to_s)
end

#result_keyObject



43
44
45
46
47
48
49
# File 'lib/rack/ecg/check/sequel_connection.rb', line 43

def result_key
  if name
    "sequel #{name.downcase}".gsub(/\W+/, "_")
  else
    "sequel"
  end
end