class NexmoDeveloper::BuildingBlockRedirect

Public Class Methods

new(app) click to toggle source
# File lib/nexmo_developer/app/middleware/nexmo_developer/building_block_redirect.rb, line 3
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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) click to toggle source
# 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