Class: Rack::DomainDirector
- Inherits:
-
Object
- Object
- Rack::DomainDirector
- Defined in:
- lib/rack/domain_director/request.rb,
lib/rack/domain_director/version.rb,
lib/rack/domain_director.rb
Defined Under Namespace
Classes: Request
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ DomainDirector
constructor
A new instance of DomainDirector.
Constructor Details
#initialize(app, opts = {}) ⇒ DomainDirector
Returns a new instance of DomainDirector.
5 6 7 8 9 10 11 |
# File 'lib/rack/domain_director.rb', line 5 def initialize(app, opts = {}) @app = app @to = opts.fetch(:to) @from = opts.fetch(:from) @status = opts.fetch(:status, 301) @before_redirect = opts.fetch(:before_redirect, ->(req) {}) end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/rack/domain_director.rb', line 13 def call(env) req = Rack::DomainDirector::Request.new(env) if redirectable?(req) redirect(req) else @app.call(env) end end |