Class: Etna::Redirect
- Inherits:
-
Object
- Object
- Etna::Redirect
- Defined in:
- lib/etna/redirect.rb
Instance Method Summary collapse
-
#initialize(request) ⇒ Redirect
constructor
A new instance of Redirect.
- #to(path) {|response| ... } ⇒ Object
Constructor Details
#initialize(request) ⇒ Redirect
Returns a new instance of Redirect.
7 8 9 |
# File 'lib/etna/redirect.rb', line 7 def initialize(request) @request = request end |
Instance Method Details
#to(path) {|response| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/etna/redirect.rb', line 11 def to(path, &block) return Rack::Response.new( [ { errors: [ 'Cannot redirect out of domain' ] }.to_json ], 422, { 'Content-Type' => 'application/json' } ).finish unless matches_domain?(path) response = Rack::Response.new response.redirect(path.gsub("http://", "https://"), 302) yield response if block_given? response.finish end |