module Roda::RodaPlugins::AutoloadNamedRoutes::ClassMethods

  1. lib/roda/plugins/autoload_named_routes.rb

Methods

Public Instance

  1. autoload_named_route
  2. freeze

Public Instance methods

autoload_named_route(namespace=nil, name, file)

Autoload the given file when there is request for the named route. The given file should configure the named route specified.

[show source]
   # File lib/roda/plugins/autoload_named_routes.rb
42 def autoload_named_route(namespace=nil, name, file)
43   file = File.expand_path(file)
44   autoload_named_route_files << file
45   routes = namespaced_routes[namespace] ||= {}
46   meth = routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1) do |r|
47     loc = method(routes[name]).source_location
48     require file
49     # Avoid infinite loop in case method is not overridden
50     if method(meth).source_location != loc
51       send(meth, r)
52     end
53   end
54   nil
55 end
freeze()

Eagerly load all autoloaded named routes when freezing the application.

[show source]
   # File lib/roda/plugins/autoload_named_routes.rb
58 def freeze
59   unless opts.frozen?
60     autoload_named_route_files.each{|file| require file}
61     opts[:autoload_named_route_files] = nil
62     opts.delete(:autoload_named_route_files)
63   end
64   super
65 end