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 +4 -4
- data/lib/tasks/traceroute.rake +2 -0
- data/lib/traceroute.rb +17 -14
- data/test/app.rb +2 -0
- data/test/test_helper.rb +2 -0
- data/test/traceroute_test.rb +6 -12
- data/test/traceroute_with_engine_test.rb +2 -0
- data/test/yaml_test.rb +2 -0
- data/traceroute.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0640e66c5ac5198335793c160a5af9a255b974018176dd7155f43d54cc17723b
|
4
|
+
data.tar.gz: cf4a741da1ccbad8fbe0319a6501ac91415c1f9c625fe161c9b9fb619a3391d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e2e79af23d008f8fab956dd2b42589002606a25fd972076c5b010afc2ed5505226296f7fed567302eb5e8dd240ce0b549cc17523ee5dadfbe0b846ae6a5396
|
7
|
+
data.tar.gz: b640ac967c3d7ad64d7e894fe803d7bf0fa0b4696f26ee367a69f3656898c63b193c24d8a580741f896cfcb9f544170acd15254b36e15502ef1f593f93b18cbd
|
data/lib/tasks/traceroute.rake
CHANGED
data/lib/traceroute.rb
CHANGED
@@ -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].
|
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.
|
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
|
data/test/app.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/traceroute_test.rb
CHANGED
@@ -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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
data/test/yaml_test.rb
CHANGED
data/traceroute.gemspec
CHANGED
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.
|
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-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|