Skip to content

Commit

Permalink
refactor: router.rb to improve code readability and maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotelesbr committed Jan 3, 2024
1 parent ab6a0c9 commit 18dd212
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/lenna/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def add_route(method, path, &block)
end

current_node.endpoint = true
current_node.blocks[method.upcase] = block # Armazena o bloco com a chave do método
current_node.blocks[method.upcase] = block
end

# This method will create the nodes that are missing.
Expand All @@ -106,7 +106,7 @@ def add_route(method, path, &block)
# @private `Since v0.1`
# See {Route::Builder#find_route}
#
def find_route(method, path)
def find_route(method, path) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
cache_key = "#{method}#{path}"

return @route_cache[cache_key] if @route_cache.key?(cache_key)
Expand All @@ -123,7 +123,8 @@ def find_route(method, path)
params[key[1..].to_sym] = segment
current_node = node
else
return nil # Rota não encontrada
# No route found
return nil
end
end

Expand Down

0 comments on commit 18dd212

Please sign in to comment.