module Roda::RodaPlugins::AutoloadNamedRoutes

  1. lib/roda/plugins/autoload_named_routes.rb

The autoload_named_routes plugin builds on the named_routes plugin and allows for delaying loading of a file containing a named route for an application until there is a request that uses the named route. This can be useful in development to improvement startup time by not loading all named routes up front. It can also be useful in testing subsets of an application by only loading the named routes being tested.

You can specify a single hash branch for autoloading:

plugin :autoload_named_route
autoload_named_route(:route_name, '/absolute/path/to/file')
autoload_named_route(:namespace, :route_name, 'relative/path/to/file')

Note that unlike the route method defined by the named_routes plugin, when providing a namespace, the namespace comes before the route name and not after.

When the autoloaded file is required, it should redefine the same named route. If it does not, requests to the named route will be ignored (as if the related named route block was empty).

When freezing an application, all named routes are automatically loaded, because autoloading named routes does not work for frozen applications.


Public Class

  1. configure
  2. load_dependencies

Public Class methods

[show source]
   # File lib/roda/plugins/autoload_named_routes.rb
33 def self.configure(app)
34   app.opts[:autoload_named_route_files] ||= []
35 end
[show source]
   # File lib/roda/plugins/autoload_named_routes.rb
29 def self.load_dependencies(app)
30   app.plugin :named_routes
31 end