lib/roda/plugins/class_level_routing.rb in roda-3.16.0 vs lib/roda/plugins/class_level_routing.rb in roda-3.17.0
- old
+ new
@@ -50,14 +50,10 @@
# Note that class level routing is implemented via a simple array of routes, so routing performance
# will degrade linearly as the number of routes increases. For best performance, you should use
# the normal +route+ class method to define your routing tree. This plugin does make it simpler to
# add additional routes after the routing tree has already been defined, though.
module ClassLevelRouting
- def self.load_dependencies(app)
- app.plugin :_after_hook
- end
-
# Initialize the class_routes array when the plugin is loaded. Also, if the application doesn't
# currently have a routing block, setup an empty routing block so that things will still work if
# a routing block isn't added.
def self.configure(app)
app.route{} unless app.route_block
@@ -66,11 +62,11 @@
module ClassMethods
# Define routing methods that will store class level routes.
[:root, :on, :is, :get, :post, :delete, :head, :options, :link, :patch, :put, :trace, :unlink].each do |meth|
define_method(meth) do |*args, &block|
- opts[:class_level_routes] << [meth, args, block].freeze
+ opts[:class_level_routes] << [meth, args, convert_route_block(block)].freeze
end
end
# Freeze the class level routes so that there can be no thread safety issues at runtime.
def freeze
@@ -92,9 +88,10 @@
def _roda_after_10__class_level_routing(result)
if result && result[0] == 404 && (v = result[2]).is_a?(Array) && v.empty?
# Reset the response so it doesn't inherit the status or any headers from
# the original response.
@_response.send(:initialize)
+ @_response.status = nil
result.replace(_call do |r|
opts[:class_level_routes].each do |meth, args, blk|
r.instance_variable_set(:@remaining_path, @_original_remaining_path)
r.public_send(meth, *args) do |*a|
instance_exec(*a, &blk)