pseudomuto/routesjs-rails — pull request #9 by pseudomuto (2014-10-02 21:40:02+00:00)
Title: Include and Exclude Routes

Resolves #7

# The Problem

Some route files are huge, or contain routes that don't need to be included in the JS output. Currently there is no way to specify that only a subset of the routes should be made available to JS.

# The Solution

Adding the ability to define include and/or exclude regex's for deciding which routes should be included in the output. These are defined inside the initializer (updated in this PR).

```ruby
# in config/initializer/routesjs-rails.rb

RoutesJS::Routes.include_patterns = [
/nameSpace/,
/api/i
]

RoutesJS::Routes.exclude_patterns = [
/\Arails/i
]
```

Inclusion and exclusion can work independently or in conjunction with each other.

Include | Exclude | Result
:--------: | :--------: | ---------
no | no | No Op - All routes are included
yes | no | Only routes that match one or more of the include patterns are included
no | yes | All routes except ones that match one or more of the exclude patterns are included
yes | yes | Routes that match one or more of the include patterns and _do not_ match any of the exclude patterns are included

By default, the [Rails internal routes](https://github.com/rails/rails/blob/29006a7795eb842ab0a07f936f1ecc858319664b/actionpack/lib/action_dispatch/routing/inspector.rb#L65) are not included.