Module: Konmari::Routes
- Defined in:
- lib/konmari/routes.rb,
lib/konmari/routes/loader.rb,
lib/konmari/routes/version.rb,
lib/konmari/routes/configuration.rb,
lib/konmari/routes/rails_reloader.rb
Defined Under Namespace
Classes: Configuration, FilenameError, Loader, RailsReloader
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
-
.config {|config| ... } ⇒ Object
Given a routes directory, recursively load all routes.
Class Method Details
.config {|config| ... } ⇒ Object
Given a routes directory, recursively load all routes.
Recursively loads all routes in a directory following this algorithm:
-
Load the files in each directory that match PRIORITY_FILES in order listed
-
Load each directory, opening a *new namespace* matching the directory name, and start back at step 1
-
Load all other files in alphabetical order
Be aware that any routes will be respected in the order they are loaded Routes files must use extension .routes
Example file structure:
|- routes/
| |- index.routes
| |- comments.routes
| |- users/
| |- index.routes
| |- friends.routes
Analogous routes definitions
application.routes.draw do
# all index routes
# all comments routes (likely a resource, *must* have first code line of `resource/namespace :comments`)
namespace :users do
# all index routes from `index.routes` file in `users/`
# all friends routes from `friends.routes` in `users/`
end
end
The friends.routes file could then be as simple as:
# routes/users/friends.routes
# NOTE: the resource matches the filename
resources :friends, only: [:index, :create, :delete], path: :my_friends # or any other options passed to resource(s)
Point being, declaring the namespace is unnecessary. This gives us the huge advantage of being able to have our routes files exactly match the file heirarchy of our controllers. We also have the flexibility, through the prioritized files, to add any other routes we might need without being restrained by the filename constraint.
In your config/routes.rb file, use this method to configure and then load all routes for the specified application from the provided folder path.
14 15 16 |
# File 'lib/konmari/routes.rb', line 14 def self.config Loader.new(Configuration.new.tap { |config| yield config}) if block_given? end |