Module: Roda::RodaPlugins::AutoloadNamedRoutes

Defined in:
lib/roda/plugins/autoload_named_routes.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



33
34
35
# File 'lib/roda/plugins/autoload_named_routes.rb', line 33

def self.configure(app)
  app.opts[:autoload_named_route_files] ||= []
end

.load_dependencies(app) ⇒ Object



29
30
31
# File 'lib/roda/plugins/autoload_named_routes.rb', line 29

def self.load_dependencies(app)
  app.plugin :named_routes
end