Class: Gesund::Output::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/gesund/output/rack.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checksObject

Returns the value of attribute checks.



14
15
16
# File 'lib/gesund/output/rack.rb', line 14

def checks
  @checks
end

Class Method Details

.start(checks, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/gesund/output/rack.rb', line 5

def self.start(checks, options={})
  app = self.new
  app.checks = checks
  # http://rubydoc.info/github/rack/rack/master/Rack/Server#initialize-instance_method
  options[:Port] = options.delete 'port'
  options[:Host] = options.delete 'host'
  ::Rack::Server.start({ :app => app }.merge(options))
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gesund/output/rack.rb', line 16

def call(env)
  results = Gesund::CheckRunner.run(self.checks)
  body = []
  failflag = false
  results.each do |check|
     failflag = true if check.first.to_i != 200
     body << "#{check.first}: #{check.last.join}\n"
  end
  status = failflag ? 500 : 200
  header = { "Content-Type" => "text/plain" }
  [status, header, body]
end