Class: HireFire::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/hirefire/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Initialize the HireFire::Middleware and store the ‘app` in `@app` and `ENV` in `@token` for convenience.



11
12
13
14
# File 'lib/hirefire/middleware.rb', line 11

def initialize(app)
  @app   = app
  @token = ENV["HIREFIRE_TOKEN"]
end

Instance Method Details

#call(env) ⇒ Object

Will respond to the request here if either the ‘test` or the `info` url was requested. Otherwise, fall through to the rest of the middleware below HireFire::Middleware.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hirefire/middleware.rb', line 21

def call(env)
  @env = env

  if test?
    [ 200, {"Content-Type" => "text/html"}, self ]
  elsif info?
    [ 200, {"Content-Type" => "application/json"}, self ]
  else
    @app.call(env)
  end
end

#each(&block) ⇒ text/html, application/json

Returns text/html when the ‘test` url is requested. This is purely to see whether the URL works through the HireFire command-line utility.

Returns a JSON String when the ‘info` url is requested. This url will be requested every minute by HireFire in order to fetch dyno data.



41
42
43
44
45
46
47
# File 'lib/hirefire/middleware.rb', line 41

def each(&block)
  if test?
    block.call "HireFire Middleware Found!"
  elsif info?
    block.call(dynos)
  end
end