Class: Rack::EY::Solo::DomainRedirect
- Inherits:
-
Object
- Object
- Rack::EY::Solo::DomainRedirect
- Defined in:
- lib/rack-redirect.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) {|_self| ... } ⇒ DomainRedirect
constructor
A new instance of DomainRedirect.
Constructor Details
#initialize(app) {|_self| ... } ⇒ DomainRedirect
Returns a new instance of DomainRedirect.
8 9 10 11 12 |
# File 'lib/rack-redirect.rb', line 8 def initialize(app, &block) @app = app @prefix = nil yield self if block_given? end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/rack-redirect.rb', line 7 def prefix @prefix end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack-redirect.rb', line 14 def call(env) parts = env['SERVER_NAME'].split('.') suffix, chunk, prefix = parts.pop, parts.pop, parts.pop if prefix == @prefix @app.call(env) else prefix = @prefix ? "#{@prefix}." : '' destination = "#{env['rack.url_scheme']}://#{prefix}#{chunk}.#{suffix}" destination << "#{env['PATH_INFO']}" destination << "?#{env['QUERY_STRING']}" unless env['QUERY_STRING'].empty? [301, {'Location' => destination}, ['See Ya!']] end end |