lib/roda/plugins/named_routes.rb in roda-3.50.0 vs lib/roda/plugins/named_routes.rb in roda-3.51.0

- old
+ new

@@ -36,10 +36,13 @@ # end # # Note that in multi-threaded code, you should not attempt to add a # named route after accepting requests. # + # To handle development environments that reload code, you can call the + # +route+ class method without a block to remove an existing named route. + # # == Routing Files # # The convention when using the named_routes plugin is to have a single # named route per file, and these routing files should be stored in # a routes subdirectory in your application. So for the above example, you @@ -122,11 +125,11 @@ end # The names for the currently stored named routes def named_routes(namespace=nil) unless routes = opts[:namespaced_routes][namespace] - raise RodaError, "unsupported multi_route namespace used: #{namespace.inspect}" + raise RodaError, "unsupported named_routes namespace used: #{namespace.inspect}" end routes.keys end # Return the named route with the given name. @@ -138,10 +141,15 @@ # store the route block. Otherwise, this is the main route, so # call super. def route(name=nil, namespace=nil, &block) if name routes = opts[:namespaced_routes][namespace] ||= {} - routes[name] = define_roda_method(routes[name] || "multi_route_#{namespace}_#{name}", 1, &convert_route_block(block)) + if block + routes[name] = define_roda_method(routes[name] || "named_routes_#{namespace}_#{name}", 1, &convert_route_block(block)) + elsif meth = routes[name] + routes.delete(name) + remove_method(meth) + end else super(&block) end end end