module Roda::RodaPlugins::AutoloadHashBranches

  1. lib/roda/plugins/autoload_hash_branches.rb

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

You can specify a single hash branch for autoloading:

plugin :autoload_hash_branches
autoload_hash_branch('branch_name', '/absolute/path/to/file')
autoload_hash_branch('namespace', 'branch_name', 'relative/path/to/file')

You can also set the plugin to autoload load all hash branch files in a given directory. This will look at each .rb file in the directory, and add an autoload for it, using the filename without the .rb as the branch name:

autoload_hash_branch_dir('/path/to/dir')
autoload_hash_branch_dir('namespace', '/path/to/dir')

In both cases, when the autoloaded file is required, it should redefine the same hash branch. If it does not, requests to the hash branch will result in a 404 error.

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

Methods

Public Class

  1. configure
  2. load_dependencies

Public Class methods

configure(app)
[show source]
   # File lib/roda/plugins/autoload_hash_branches.rb
36 def self.configure(app)
37   app.opts[:autoload_hash_branch_files] ||= []
38 end
load_dependencies(app)
[show source]
   # File lib/roda/plugins/autoload_hash_branches.rb
32 def self.load_dependencies(app)
33   app.plugin :hash_branches
34 end