Class: VanitySlug::VanityRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/vanity_slug/vanity_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ VanityRouter

Returns a new instance of VanityRouter.



3
4
5
# File 'lib/vanity_slug/vanity_router.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/vanity_slug/vanity_router.rb', line 7

def call(env)
  begin
    Rails.application.routes.recognize_path env["PATH_INFO"] 
  rescue
    if path = VanitySlug.find(env)
      env["PATH_INFO"] = path
    end
  end

  @app.call(env)
end