Class: Aker::Rack::Setup
- Inherits:
-
Object
- Object
- Aker::Rack::Setup
- Defined in:
- lib/aker/rack/setup.rb
Overview
The middleware which makes the aker environment available in the rake environment and authenticates the credentials that the request provides (if any). It is responsible for determining whether the request is interactive or not and will use the appropriate configured mode based on this decision.
You probably don’t want to ‘use` this directly; use use_in to configure in this middleware and all its dependencies simultaneously.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Implements the rack middleware behavior.
-
#initialize(app, configuration) ⇒ Setup
constructor
Creates a new instance of the middleware.
-
#interactive?(env) ⇒ Boolean?
Determines if the given rack env represents an interactive request.
Constructor Details
#initialize(app, configuration) ⇒ Setup
Creates a new instance of the middleware.
28 29 30 31 |
# File 'lib/aker/rack/setup.rb', line 28 def initialize(app, configuration) @app = app @configuration = configuration end |
Instance Method Details
#call(env) ⇒ Array
Implements the rack middleware behavior.
This class exposes three environment variables to downstream middleware and the app:
* `"aker.configuration"`: the {Aker::Configuration configuration}
for this application.
* `"aker.authority"`: the {Aker::Authorities authority} for
this application.
* `"aker.interactive"`: a boolean indicating whether this
request is being treated as an interactive (UI) or
non-interactive (API) request
[There is a related fourth environment variable:
* `"aker.check"`: an instance of {Aker::Rack::Facade}
permitting authentication and authorization queries about the
current user (if any).
This fourth variable is added by the Authenticate middleware; see its documentation for more.]
58 59 60 61 62 63 64 |
# File 'lib/aker/rack/setup.rb', line 58 def call(env) env['aker.configuration'] = @configuration env['aker.authority'] = @configuration. env['aker.interactive'] = interactive?(env) @app.call(env) end |
#interactive?(env) ⇒ Boolean?
Determines if the given rack env represents an interactive request.
71 72 73 74 75 |
# File 'lib/aker/rack/setup.rb', line 71 def interactive?(env) @configuration.api_modes.empty? or env["HTTP_ACCEPT"] =~ %r{text/html} or env["HTTP_USER_AGENT"] =~ %r{Mozilla} end |