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', '/path/to/file')
autoload_hash_branch('namespace', 'branch_name', '/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.
This plugin will not work correctly when freezing applications, because it requires modifying the class at runtime as hash branches are autoloaded.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.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 |