traceroute 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90fc80962b328c76194cf2766d02a2c2ad0bd462cb96e26686aeb15779c51085
4
- data.tar.gz: 4e3ebbe7177df01147fbc9ce985ed2d94b3ac68c5be95dbf31c6c94955acb42d
3
+ metadata.gz: 0640e66c5ac5198335793c160a5af9a255b974018176dd7155f43d54cc17723b
4
+ data.tar.gz: cf4a741da1ccbad8fbe0319a6501ac91415c1f9c625fe161c9b9fb619a3391d2
5
5
  SHA512:
6
- metadata.gz: 2feb27fe20d57f5683e396d86393b303fffc7627a5489224c6ca089fa957cb002811f87e5469e2565bea2883b1bf0d025c243429b0a9277733dfa4a20783cad9
7
- data.tar.gz: acd2e0940b33e1f0e5c55a9de35251240026bbffbb4fff139690b3ebbd8161d0120562d636500d55d3ddc69e11d9783ef845eb88229dfa271b9177b1972fa59b
6
+ metadata.gz: d8e2e79af23d008f8fab956dd2b42589002606a25fd972076c5b010afc2ed5505226296f7fed567302eb5e8dd240ce0b549cc17523ee5dadfbe0b846ae6a5396
7
+ data.tar.gz: b640ac967c3d7ad64d7e894fe803d7bf0fa0b4696f26ee367a69f3656898c63b193c24d8a580741f896cfcb9f544170acd15254b36e15502ef1f593f93b18cbd
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  desc 'Prints out unused routes and unreachable action methods'
2
4
  task :traceroute => :environment do
3
5
  traceroute = Traceroute.new Rails.application
@@ -1,5 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Traceroute
2
4
  VERSION = Gem.loaded_specs['traceroute'].version.to_s
5
+
6
+ WILDCARD_ROUTES = %r[^/?:controller\(?/:action].freeze
7
+
3
8
  class Railtie < ::Rails::Railtie
4
9
  rake_tasks do
5
10
  load File.join(File.dirname(__FILE__), 'tasks/traceroute.rake')
@@ -31,12 +36,16 @@ class Traceroute
31
36
 
32
37
  def routed_actions
33
38
  routes.map do |r|
34
- if r.requirements[:controller].blank? && r.requirements[:action].blank? && (r.path == '/:controller(/:action(/:id(.:format)))')
35
- %Q["#{r.path}" This is a legacy wild controller route that's not recommended for RESTful applications.]
36
- else
39
+ if r.requirements[:controller].present? && r.requirements[:action].present?
37
40
  "#{r.requirements[:controller]}##{r.requirements[:action]}"
41
+ elsif (String === r.path) && (WILDCARD_ROUTES =~ r.path)
42
+ %Q["#{r.path}" ⚠️ This is a legacy wild controller route that's not recommended for RESTful applications.]
43
+ elsif WILDCARD_ROUTES =~ r.path.spec.to_s
44
+ %Q["#{r.path.spec}" ⚠️ This is a legacy wild controller route that's not recommended for RESTful applications.]
45
+ else
46
+ ((String === r.path) && r.path.to_s) || r.path.spec.to_s # unknown routes
38
47
  end
39
- end.flatten.reject {|r| @ignored_unused_routes.any? { |m| r.match(m) } }
48
+ end.compact.flatten.reject {|r| @ignored_unused_routes.any? { |m| r.match(m) } }
40
49
  end
41
50
 
42
51
  private
@@ -60,7 +69,9 @@ class Traceroute
60
69
 
61
70
  def load_ignored_regex!
62
71
  @ignored_unreachable_actions = [/^rails\//]
63
- @ignored_unused_routes = [/^rails\//]
72
+ @ignored_unused_routes = [/^rails\//, /^\/cable$/]
73
+
74
+ @ignored_unused_routes << %r{^#{@app.config.assets.prefix}} if @app.config.respond_to? :assets
64
75
 
65
76
  return unless at_least_one_file_exists?
66
77
 
@@ -87,7 +98,7 @@ class Traceroute
87
98
 
88
99
  def collect_routes(routes)
89
100
  routes = routes.each_with_object([]) do |r, tmp_routes|
90
- next if r.name.nil? && r.requirements.blank?
101
+ next if (ActionDispatch::Routing::Mapper::Constraints === r.app) && (ActionDispatch::Routing::PathRedirect === r.app.app)
91
102
 
92
103
  if r.app.is_a?(ActionDispatch::Routing::Mapper::Constraints) && r.app.app.respond_to?(:routes)
93
104
  engine_routes = r.app.app.routes
@@ -101,14 +112,6 @@ class Traceroute
101
112
 
102
113
  routes.reject! {|r| r.app.is_a?(ActionDispatch::Routing::Redirect)}
103
114
 
104
- if @app.config.respond_to?(:assets)
105
- exclusion_regexp = %r{^#{@app.config.assets.prefix}}
106
-
107
- routes.reject! do |route|
108
- path = (defined?(ActionDispatch::Journey::Route) || defined?(Journey::Route)) ? route.path.spec.to_s : route.path
109
- path =~ exclusion_regexp
110
- end
111
- end
112
115
  routes
113
116
  end
114
117
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
  require 'action_controller/railtie'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  require 'minitest/autorun'
3
5
  require 'rails'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
 
3
5
  module TracerouteTest
@@ -51,21 +53,15 @@ module TracerouteTest
51
53
  end
52
54
 
53
55
  def test_dont_fail_when_envvar_is_anything_but_1
54
- traceroute = Traceroute.new Rails.application
55
-
56
56
  ENV['FAIL_ON_ERROR'] = "DERP"
57
57
  Rake::Task[:traceroute].execute
58
58
  end
59
59
 
60
60
  def test_rake_task_fails_when_unreachable_action_method_detected
61
- traceroute = Traceroute.new Rails.application
62
-
63
- begin
64
- ENV['FAIL_ON_ERROR']="1"
65
- Rake::Task[:traceroute].execute
66
- rescue => e
67
- assert_includes e.message, "Unused routes or unreachable action methods detected."
68
- end
61
+ ENV['FAIL_ON_ERROR']="1"
62
+ Rake::Task[:traceroute].execute
63
+ rescue => e
64
+ assert_includes e.message, "Unused routes or unreachable action methods detected."
69
65
  end
70
66
 
71
67
  def test_rake_task_fails_when_unused_route_detected
@@ -89,8 +85,6 @@ module TracerouteTest
89
85
  end
90
86
  end
91
87
 
92
- traceroute = Traceroute.new Rails.application
93
-
94
88
  begin
95
89
  ENV['FAIL_ON_ERROR'] = "1"
96
90
  Rake::Task[:traceroute].execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
 
3
5
  module TestEngine
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
 
3
5
  module JasmineRails
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "traceroute"
6
- s.version = '0.6.0'
6
+ s.version = '0.6.1'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Akira Matsuda']
9
9
  s.email = ['ronnie@dio.jp']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traceroute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails