Class: RouteGuard::Rules::DuplicateHelpers
- Defined in:
- lib/route_guard/rules/duplicate_helpers.rb
Instance Attribute Summary
Attributes inherited from Base
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 33 34 35 36 37 38 39 40 |
# File 'lib/route_guard/rules/duplicate_helpers.rb', line 9 def analyze(routes, report) issues = [] groups = Hash.new { |h, k| h[k] = [] } routes.each do |route| next if route.name.nil? || route.name.empty? groups[route.name] << route end groups.each do |name, grp_routes| paths = grp_routes.map(&:path).uniq next if paths.length <= 1 primary = grp_routes.first conflicts = grp_routes[1..-1] conflicts.each do |conflict| next if conflict.path == primary.path issues << Models::Issue.new( rule_name: :duplicate_helpers, severity: :error, message: "Duplicate Named Helper: Helper '#{name}_path' is defined for both '#{primary.path}' and '#{conflict.path}'.", route: conflict, related_routes: [primary] ) end end issues end |