Module: Roda::RodaPlugins::AutoloadHashBranches

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

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



36
37
38
# File 'lib/roda/plugins/autoload_hash_branches.rb', line 36

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

.load_dependencies(app) ⇒ Object



32
33
34
# File 'lib/roda/plugins/autoload_hash_branches.rb', line 32

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