Class: Etna::Redirect

Inherits:
Object
  • Object
show all
Defined in:
lib/etna/redirect.rb

Instance Method Summary collapse

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

Yields:

  • (response)


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