Class: RouteGuard::Rules::UnreachableRoutes

Inherits:
Base
  • Object
show all
Defined in:
lib/route_guard/rules/unreachable_routes.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#expand_path, #initialize, #path_shadows?, #split_segments, #verb_matches?

Constructor Details

This class inherits a constructor from RouteGuard::Rules::Base

Instance Method Details

#analyze(routes, report) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/route_guard/rules/unreachable_routes.rb', line 9

def analyze(routes, report)
  issues = []
  catch_alls = []

  routes.each do |route|
    matching_catch_all = catch_alls.find do |ca|
      verb_matches?(ca.verb, route.verb)
    end

    if matching_catch_all
      issues << Models::Issue.new(
        rule_name: :unreachable_routes,
        severity: :error,
        message: "Unreachable Route: #{route} is unreachable because it comes after catch-all wildcard #{matching_catch_all}.",
        route: route,
        related_routes: [matching_catch_all]
      )
    elsif catch_all_wildcard?(route)
      catch_alls << route
    end
  end

  issues
end