Public Instance methods
autoload_hash_branch(namespace='', segment, file)
Autoload the given file when there is request for the hash branch. The given file should configure the hash branch specified.
[show source]
# File lib/roda/plugins/autoload_hash_branches.rb 45 def autoload_hash_branch(namespace='', segment, file) 46 segment = "/#{segment}" 47 file = File.expand_path(file) 48 autoload_hash_branch_files << file 49 routes = hash_branches[namespace] ||= {} 50 meth = routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1) do |r| 51 loc = method(routes[segment]).source_location 52 require file 53 # Avoid infinite loop in case method is not overridden 54 if method(meth).source_location != loc 55 send(meth, r) 56 end 57 end 58 nil 59 end
autoload_hash_branch_dir(namespace='', dir)
For each .rb file in the given directory, add an autoloaded hash branch based on the file name.
[show source]
# File lib/roda/plugins/autoload_hash_branches.rb 63 def autoload_hash_branch_dir(namespace='', dir) 64 Dir.new(dir).entries.each do |file| 65 if file =~ /\.rb\z/i 66 autoload_hash_branch(namespace, file.sub(/\.rb\z/i, ''), File.join(dir, file)) 67 end 68 end 69 end
freeze()
Eagerly load all hash branches when freezing the application.
[show source]
# File lib/roda/plugins/autoload_hash_branches.rb 72 def freeze 73 unless opts.frozen? 74 autoload_hash_branch_files.each{|file| require file} 75 opts[:autoload_hash_branch_files] = nil 76 opts.delete(:autoload_hash_branch_files) 77 end 78 super 79 end