module Roda::RodaPlugins::AutoloadHashBranches::ClassMethods
Public Instance Methods
Source
# File lib/roda/plugins/autoload_hash_branches.rb, line 43 def autoload_hash_branch(namespace='', segment, file) segment = "/#{segment}" file = File.expand_path(file) opts[:autoload_hash_branch_files] << file routes = opts[:hash_branches][namespace] ||= {} meth = routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1) do |r| loc = method(routes[segment]).source_location require file # Avoid infinite loop in case method is not overridden if method(meth).source_location != loc send(meth, r) end end nil end
Autoload the given file when there is request for the hash branch. The given file should configure the hash branch specified.
Source
# File lib/roda/plugins/autoload_hash_branches.rb, line 61 def autoload_hash_branch_dir(namespace='', dir) Dir.new(dir).entries.each do |file| if file =~ /\.rb\z/i autoload_hash_branch(namespace, file.sub(/\.rb\z/i, ''), File.join(dir, file)) end end end
For each .rb file in the given directory, add an autoloaded hash branch based on the file name.
Source
# File lib/roda/plugins/autoload_hash_branches.rb, line 70 def freeze opts.delete(:autoload_hash_branch_files).each{|file| require file} unless opts.frozen? super end
Eagerly load all hash branches when freezing the application.
Calls superclass method