Socket
Book a DemoInstallSign in
Socket

route_matcher

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route_matcher

0.0.6
bundlerRubygems
Version published
Maintainers
2
Created
Source

RouteMatcher

Your Rails 3 route helper for pretty URLs sharing the same dynamic path "part"

For example, have both routes on the same path part

# in config/routes.rb
':brand'          => 'brands#show'       # /nike
':brand_category' => 'brands#category'   # /fashion

With rails 3 you can use constrains to seperate between them. But what if you those constrains are data driven? Then RouteMatcher may come in handy:

# in config/routes.rb
':brand' => 'brands#show', constraints => RouteMatcher::UrlMatcher.new('brands') { Brand.map{|b| "/#{b.slug}" } }

# in brand.rb
after_save { RouteMatcher::UrlMatcher.mark_dirty('brands') }
  • Matcher lazy loads, it prevents database calls at the start of the app (and rake tasks for example)
  • It caches the allowed URLs in memory to prevent database calls on each request
  • Uses a timestamp in Rails.cache for cache invalidation

Known issues

  • If you have a multi process production environment (which is pretty likely), it will only work with a shared Rails cache, like memcache (cause of the timestamps)

FAQs

Package last updated on 05 Jun 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.