mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Rename to FilterBlock
This commit is contained in:
		
							parent
							
								
									8ec9ed8331
								
							
						
					
					
						commit
						d3eea1d9ab
					
				
					 1 changed files with 8 additions and 9 deletions
				
			
		|  | @ -6,7 +6,7 @@ module Kemal::Middleware | ||||||
| 
 | 
 | ||||||
|     # This middleware is lazily instantiated and added to the handlers as soon as a call to `after_X` or `before_X` is made. |     # This middleware is lazily instantiated and added to the handlers as soon as a call to `after_X` or `before_X` is made. | ||||||
|     def initialize |     def initialize | ||||||
|       @tree = Radix::Tree(Array(Kemal::Middleware::Block)).new |       @tree = Radix::Tree(Array(Kemal::Middleware::FilterBlock)).new | ||||||
|       Kemal.config.add_filter_handler(self) |       Kemal.config.add_filter_handler(self) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | @ -28,10 +28,10 @@ module Kemal::Middleware | ||||||
|     # It adds the block for the corresponding verb/path/type combination to the tree. |     # 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 -> _) |     def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> _) | ||||||
|       lookup = lookup_filters_for_path_type(verb, path, type) |       lookup = lookup_filters_for_path_type(verb, path, type) | ||||||
|       if lookup.found? && lookup.payload.is_a?(Array(Block)) |       if lookup.found? && lookup.payload.is_a?(Array(FilterBlock)) | ||||||
|         (lookup.payload.as(Array(Block))) << Block.new(&block) |         (lookup.payload.as(Array(FilterBlock))) << FilterBlock.new(&block) | ||||||
|       else |       else | ||||||
|         @tree.add radix_path(verb, path, type), [Block.new(&block)] |         @tree.add radix_path(verb, path, type), [FilterBlock.new(&block)] | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | @ -48,8 +48,8 @@ module Kemal::Middleware | ||||||
|     # This will fetch the block for the verb/path/type from the tree and call it. |     # This will fetch the block for the verb/path/type from the tree and call it. | ||||||
|     private def call_block_for_path_type(verb, path, type, context) |     private def call_block_for_path_type(verb, path, type, context) | ||||||
|       lookup = lookup_filters_for_path_type(verb, path, type) |       lookup = lookup_filters_for_path_type(verb, path, type) | ||||||
|       if lookup.found? && lookup.payload.is_a? Array(Block) |       if lookup.found? && lookup.payload.is_a? Array(FilterBlock) | ||||||
|         blocks = lookup.payload.as(Array(Block)) |         blocks = lookup.payload.as(Array(FilterBlock)) | ||||||
|         blocks.each { |block| block.call(context) } |         blocks.each { |block| block.call(context) } | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|  | @ -57,7 +57,7 @@ module Kemal::Middleware | ||||||
|     # This checks is filter is already defined for the verb/path/type combination |     # This checks is filter is already defined for the verb/path/type combination | ||||||
|     private def filter_for_path_type_defined?(verb, path, type) |     private def filter_for_path_type_defined?(verb, path, type) | ||||||
|       lookup = @tree.find radix_path(verb, path, type) |       lookup = @tree.find radix_path(verb, path, type) | ||||||
|       lookup.found? && lookup.payload.is_a? Block |       lookup.found? && lookup.payload.is_a? FilterBlock | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     # This returns a lookup for verb/path/type |     # This returns a lookup for verb/path/type | ||||||
|  | @ -71,7 +71,7 @@ module Kemal::Middleware | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   # :nodoc: |   # :nodoc: | ||||||
|   class Block |   class FilterBlock | ||||||
|     property block : HTTP::Server::Context -> String |     property block : HTTP::Server::Context -> String | ||||||
| 
 | 
 | ||||||
|     def initialize(&block : HTTP::Server::Context -> _) |     def initialize(&block : HTTP::Server::Context -> _) | ||||||
|  | @ -87,7 +87,6 @@ end | ||||||
| # All the helper methods available are: | # All the helper methods available are: | ||||||
| #  - before_all, before_get, before_post, before_put, before_patch, before_delete | #  - before_all, before_get, before_post, before_put, before_patch, before_delete | ||||||
| #  - after_all, after_get, after_post, after_put, after_patch, after_delete | #  - after_all, after_get, after_post, after_put, after_patch, after_delete | ||||||
| 
 |  | ||||||
| ALL_METHODS = %w(get post put patch delete all) | ALL_METHODS = %w(get post put patch delete all) | ||||||
| {% for type in ["before", "after"] %} | {% for type in ["before", "after"] %} | ||||||
|   {% for method in ALL_METHODS %} |   {% for method in ALL_METHODS %} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue