Class: NexmoDeveloper::BuildingBlockRedirect
- Inherits:
-
Object
- Object
- NexmoDeveloper::BuildingBlockRedirect
- Defined in:
- lib/nexmo_developer/app/middleware/nexmo_developer/building_block_redirect.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ BuildingBlockRedirect
constructor
A new instance of BuildingBlockRedirect.
- #redirect(location) ⇒ Object
Constructor Details
#initialize(app) ⇒ BuildingBlockRedirect
Returns a new instance of BuildingBlockRedirect.
3 4 5 |
# File 'lib/nexmo_developer/app/middleware/nexmo_developer/building_block_redirect.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/nexmo_developer/app/middleware/nexmo_developer/building_block_redirect.rb', line 11 def call(env) req = Rack::Request.new(env) return redirect(req.path.gsub('/building-blocks/', '/code-snippets/')) if req.path.include? '/building-blocks/' @app.call(env) end |
#redirect(location) ⇒ Object
7 8 9 |
# File 'lib/nexmo_developer/app/middleware/nexmo_developer/building_block_redirect.rb', line 7 def redirect(location) [301, { 'Location' => location, 'Content-Type' => 'text/html' }, ['Moved Permanently']] end |