mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Update filters to dont care about block return type
This commit is contained in:
		
							parent
							
								
									3b402586f8
								
							
						
					
					
						commit
						53df88b9fb
					
				
					 1 changed files with 7 additions and 6 deletions
				
			
		|  | @ -26,7 +26,7 @@ module Kemal::Middleware | |||
| 
 | ||||
|     # :nodoc: This shouldn't be called directly, it's not private because I need to call it for testing purpose since I can't call the macros in the spec. | ||||
|     # It adds the block for the corresponding verb/path/type combination to the tree. | ||||
|     def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> String) | ||||
|     def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> _) | ||||
|       lookup = lookup_filters_for_path_type(verb, path, type) | ||||
|       if lookup.found? && lookup.payload.is_a?(Array(Block)) | ||||
|         (lookup.payload as Array(Block)) << Block.new(&block) | ||||
|  | @ -36,12 +36,12 @@ module Kemal::Middleware | |||
|     end | ||||
| 
 | ||||
|     # This can be called directly but it's simpler to just use the macros, it will check if another filter is not already defined for this verb/path/type and proceed to call `add_route_filter` | ||||
|     def before(verb, path = "*", &block : HTTP::Server::Context -> String) | ||||
|     def before(verb, path = "*", &block : HTTP::Server::Context -> _) | ||||
|       _add_route_filter verb, path, :before, &block | ||||
|     end | ||||
| 
 | ||||
|     # This can be called directly but it's simpler to just use the macros, it will check if another filter is not already defined for this verb/path/type and proceed to call `add_route_filter` | ||||
|     def after(verb, path = "*", &block : HTTP::Server::Context -> String) | ||||
|     def after(verb, path = "*", &block : HTTP::Server::Context -> _) | ||||
|       _add_route_filter verb, path, :after, &block | ||||
|     end | ||||
| 
 | ||||
|  | @ -71,9 +71,10 @@ module Kemal::Middleware | |||
|   end | ||||
| 
 | ||||
|   class Block | ||||
|     property block : (HTTP::Server::Context -> String) | ||||
|     property block : HTTP::Server::Context -> String | ||||
| 
 | ||||
|     def initialize(&@block : HTTP::Server::Context -> String) | ||||
|     def initialize(&block : HTTP::Server::Context -> _) | ||||
|       @block = ->(context : HTTP::Server::Context) { block.call(context).to_s} | ||||
|     end | ||||
| 
 | ||||
|     def call(context) | ||||
|  | @ -89,7 +90,7 @@ end | |||
| ALL_METHODS = %w(get post put patch delete all) | ||||
| {% for type in ["before", "after"] %} | ||||
|   {% for method in ALL_METHODS %} | ||||
|     def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> String) | ||||
|     def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> _) | ||||
|      Kemal::Middleware::Filter::INSTANCE.{{type.id}}({{method}}.upcase, path, &block) | ||||
|     end | ||||
|   {% end %} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue