class AbrilHeartbeat::Middleware

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/abril_heartbeat.rb, line 22
def initialize(app, options = {})
  @app = app
  @file_path = options[:file_path]
end

Public Instance Methods

call(env) click to toggle source
# File lib/abril_heartbeat.rb, line 27
def call(env)
  @env = env
  if request.path == '/heartbeat'
    [200, { 'Content-Type' => 'text/json' }, [response.to_json]]
  else
    @app.call(env)
  end
end

Private Instance Methods

request() click to toggle source
# File lib/abril_heartbeat.rb, line 42
def request
  Rack::Request.new @env
end
response() click to toggle source
# File lib/abril_heartbeat.rb, line 38
def response
  Heartbeater.new(file_path: @file_path).run!
end