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
40 def autoload_named_route(namespace=nil, name, file)
41   file = File.expand_path(file)
42   opts[:autoload_named_route_files] << file
43   routes = opts[:namespaced_routes][namespace] ||= {}
44   meth = routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1) do |r|
45     loc = method(routes[name]).source_location
46     require file
47     # Avoid infinite loop in case method is not overridden
48     if method(meth).source_location != loc
49       send(meth, r)
50     end
51   end
52   nil
53 end
freeze()

Eagerly load all autoloaded named routes when freezing the application.

[show source]
   # File lib/roda/plugins/autoload_named_routes.rb
56 def freeze
57   opts.delete(:autoload_named_route_files).each{|file| require file} unless opts.frozen?
58   super
59 end