Class: HireFire::Middleware
- Inherits:
-
Object
- Object
- HireFire::Middleware
- Defined in:
- lib/hirefire/middleware.rb
Constant Summary collapse
- TEST_HEADERS =
Frozen headers to save some memory
{ 'Content-Type' => 'text/html' }.freeze
- INFO_HEADERS =
{ 'Content-Type' => 'application/json', 'Cache-Control' => 'must-revalidate, private, max-age=0' }.freeze
Instance Method Summary collapse
-
#call(env) ⇒ Object
Will respond to the request here if either the ‘test` or the `info` url was requested.
-
#each(&block) ⇒ text/html, application/json
Returns text/html when the ‘test` url is requested.
-
#initialize(app) ⇒ Middleware
constructor
Initialize the HireFire::Middleware and store the ‘app` in `@app` and `ENV` in `@token` for convenience.
Constructor Details
#initialize(app) ⇒ Middleware
Initialize the HireFire::Middleware and store the ‘app` in `@app` and `ENV` in `@token` for convenience.
20 21 22 23 |
# File 'lib/hirefire/middleware.rb', line 20 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.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hirefire/middleware.rb', line 30 def call(env) @env = env if test? [ 200, TEST_HEADERS, self ] elsif info? [ 200, INFO_HEADERS, 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.
50 51 52 53 54 55 56 |
# File 'lib/hirefire/middleware.rb', line 50 def each(&block) if test? block.call "HireFire Middleware Found!" elsif info? block.call(dynos) end end |