traceroute 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9d8b37c9335b489410893260a96d0bd1146358ab4907bfa6593230c126dd1c5
4
- data.tar.gz: 1a877a2573c1d01ff38a4e5710ad3854bd4ab9b508165ecf398bba83615c0558
3
+ metadata.gz: 291c384ad195a4230680d6d2a39d0f408e60d16eb0b51427d9d2fda091c162fb
4
+ data.tar.gz: 8f23318498f820271d61e9d841d8970e3dbff7de0a9d61708a77bd5243f48f2e
5
5
  SHA512:
6
- metadata.gz: 0bd199897fcaa8a7b679f29c09031a5a8a24d3e440831fd3e359dcd57e91861b6c36a76276ed2240263eddc638922b4cd076f9d8866893af75deccd08b77e59a
7
- data.tar.gz: 3e95179846678c7e1777dc94877ff93f01e4264e3f2c594d8e45221d654c57807969fb8331208ff89347d7b1c09814c7570aa9709f2cec760c60a0cd324c7438
6
+ metadata.gz: f165fa1c116887d9993c06da4a29872e4f72d816724314878e24d619bc893e074897b36b64ff819656cce2fca14b492664723e3dc7e4d3a28da2e1d39f19b7ab
7
+ data.tar.gz: '069cf2f92bd6bd7468e64c1b2bbe6f5431b855dc757613ee1aa0b87322fd02d57cbe90e7c813a2e3135e3b7d3237c65a6572e6a72a2b0ecfd721af603ed17ce6'
@@ -9,16 +9,35 @@ task :traceroute => :environment do
9
9
 
10
10
  routed_actions = traceroute.routed_actions
11
11
 
12
- unused_routes = routed_actions - defined_action_methods
13
- unreachable_action_methods = defined_action_methods - routed_actions
12
+ unless ENV['UNREACHABLE_ACTION_METHODS_ONLY']
13
+ unused_routes = routed_actions - defined_action_methods
14
+ puts "Unused routes (#{unused_routes.count}):"
15
+ unused_routes.each {|route| puts " #{route}"}
16
+ end
17
+
18
+ puts unless (ENV['UNREACHABLE_ACTION_METHODS_ONLY'] || ENV['UNUSED_ROUTES_ONLY'])
14
19
 
15
- puts "Unused routes (#{unused_routes.count}):"
16
- unused_routes.each {|route| puts " #{route}"}
17
- puts
18
- puts "Unreachable action methods (#{unreachable_action_methods.count}):"
19
- unreachable_action_methods.each {|action| puts " #{action}"}
20
+ unless ENV['UNUSED_ROUTES_ONLY']
21
+ unreachable_action_methods = defined_action_methods - routed_actions
22
+ puts "Unreachable action methods (#{unreachable_action_methods.count}):"
23
+ unreachable_action_methods.each {|action| puts " #{action}"}
24
+ end
20
25
 
21
- unless (unused_routes.empty? && unreachable_action_methods.empty?) || ENV['FAIL_ON_ERROR'] != "1"
26
+ if ENV['FAIL_ON_ERROR'] && ((!ENV['UNREACHABLE_ACTION_METHODS_ONLY'] && unused_routes.any?) || (!ENV['UNUSED_ROUTES_ONLY'] && unreachable_action_methods.any?))
22
27
  fail "Unused routes or unreachable action methods detected."
23
28
  end
24
29
  end
30
+
31
+ namespace :traceroute do
32
+ desc 'Prints out unused routes'
33
+ task :unused_routes => :environment do
34
+ ENV['UNUSED_ROUTES_ONLY'] = '1'
35
+ Rake::Task[:traceroute].invoke
36
+ end
37
+
38
+ desc 'Prints out unreachable action methods'
39
+ task :unreachable_action_methods => :environment do
40
+ ENV['UNREACHABLE_ACTION_METHODS_ONLY'] = '1'
41
+ Rake::Task[:traceroute].invoke
42
+ end
43
+ end
@@ -14,7 +14,22 @@ class Traceroute
14
14
 
15
15
  def initialize(app)
16
16
  @app = app
17
- load_ignored_regex!
17
+
18
+ @ignored_unreachable_actions = []
19
+ @ignored_unused_routes = [/^\/cable$/]
20
+
21
+ @ignored_unused_routes << %r{^#{@app.config.assets.prefix}} if @app.config.respond_to? :assets
22
+
23
+ config_filename = %w(.traceroute.yaml .traceroute.yml .traceroute).detect {|f| File.exist?(f)}
24
+ if config_filename && (config = YAML.load_file(config_filename))
25
+ (config['ignore_unreachable_actions'] || []).each do |ignored_action|
26
+ @ignored_unreachable_actions << Regexp.new(ignored_action)
27
+ end
28
+
29
+ (config['ignore_unused_routes'] || []).each do |ignored_action|
30
+ @ignored_unused_routes << Regexp.new(ignored_action)
31
+ end
32
+ end
18
33
  end
19
34
 
20
35
  def load_everything!
@@ -51,50 +66,6 @@ class Traceroute
51
66
  end.compact.flatten.reject {|r| @ignored_unused_routes.any? { |m| r.match(m) } }
52
67
  end
53
68
 
54
- private
55
- def filenames
56
- [".traceroute.yaml", ".traceroute.yml", ".traceroute"].select { |filename|
57
- File.exist? filename
58
- }.select { |filename|
59
- YAML.load_file(filename)
60
- }
61
- end
62
-
63
- def at_least_one_file_exists?
64
- return !filenames.empty?
65
- end
66
-
67
- def ignore_config
68
- filenames.each do |filename|
69
- return YAML.load_file(filename)
70
- end
71
- end
72
-
73
- def load_ignored_regex!
74
- @ignored_unreachable_actions = [/^rails\//]
75
- @ignored_unused_routes = [/^rails\//, /^\/cable$/]
76
-
77
- @ignored_unused_routes << %r{^#{@app.config.assets.prefix}} if @app.config.respond_to? :assets
78
-
79
- return unless at_least_one_file_exists?
80
-
81
- if ignore_config.has_key? 'ignore_unreachable_actions'
82
- unless ignore_config['ignore_unreachable_actions'].nil?
83
- ignore_config['ignore_unreachable_actions'].each do |ignored_action|
84
- @ignored_unreachable_actions << Regexp.new(ignored_action)
85
- end
86
- end
87
- end
88
-
89
- if ignore_config.has_key? 'ignore_unused_routes'
90
- unless ignore_config['ignore_unused_routes'].nil?
91
- ignore_config['ignore_unused_routes'].each do |ignored_action|
92
- @ignored_unused_routes << Regexp.new(ignored_action)
93
- end
94
- end
95
- end
96
- end
97
-
98
69
  def routes
99
70
  collect_routes @app.routes.routes
100
71
  end
@@ -5,3 +5,13 @@ require 'minitest/autorun'
5
5
  require 'rails'
6
6
  require 'traceroute'
7
7
  require_relative 'app'
8
+
9
+ Minitest::Test.class_eval do
10
+ def assert_defined_action_methods(*actions)
11
+ assert_equal actions.sort, @traceroute.defined_action_methods.reject {|a| a =~ /^rails/}.sort
12
+ end
13
+
14
+ def assert_routed_actions(*actions)
15
+ assert_equal actions.sort, @traceroute.routed_actions.sort
16
+ end
17
+ end
@@ -9,7 +9,7 @@ module TracerouteTest
9
9
  end
10
10
 
11
11
  def test_defined_action_methods
12
- assert_equal ['users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index'].sort, @traceroute.defined_action_methods.sort
12
+ assert_defined_action_methods 'users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index'
13
13
  end
14
14
 
15
15
  def test_routed_actions
@@ -39,7 +39,7 @@ module TracerouteTest
39
39
  end
40
40
 
41
41
  def test_routed_actions
42
- assert_equal ['admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'].sort, @traceroute.routed_actions.sort
42
+ assert_routed_actions 'admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'
43
43
  end
44
44
  end
45
45
 
@@ -56,11 +56,6 @@ module TracerouteTest
56
56
  DummyApp::Application.routes.clear!
57
57
  end
58
58
 
59
- def test_dont_fail_when_envvar_is_anything_but_1
60
- ENV['FAIL_ON_ERROR'] = "DERP"
61
- Rake::Task[:traceroute].execute
62
- end
63
-
64
59
  def test_rake_task_fails_when_unreachable_action_method_detected
65
60
  ENV['FAIL_ON_ERROR']="1"
66
61
  Rake::Task[:traceroute].execute
@@ -32,7 +32,7 @@ module TracerouteWithEngineTest
32
32
  end
33
33
 
34
34
  def test_defined_action_methods
35
- assert_equal ["admin/shops#create", "admin/shops#index", "api/books#create", "api/books#index", "test_engine/tasks#index", "users#index", "users#index2", "users#show"].sort, @traceroute.defined_action_methods.sort
35
+ assert_defined_action_methods 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'test_engine/tasks#index', 'users#index', 'users#index2', 'users#show'
36
36
  end
37
37
 
38
38
  def test_routed_actions
@@ -56,7 +56,7 @@ module TracerouteWithEngineTest
56
56
  end
57
57
 
58
58
  def test_routed_actions
59
- assert_equal ['posts#index', 'posts#show', 'posts#new', 'posts#create'].sort, @traceroute.routed_actions.sort
59
+ assert_routed_actions 'posts#index', 'posts#show', 'posts#new', 'posts#create'
60
60
  end
61
61
  end
62
62
 
@@ -83,11 +83,11 @@ module TracerouteWithEngineTest
83
83
  end
84
84
 
85
85
  def test_defined_action_methods
86
- assert_equal ["admin/shops#create", "admin/shops#index", "api/books#create", "api/books#index", "test_engine/tasks#index", "users#index", "users#index2", "users#show"].sort, @traceroute.defined_action_methods.sort
86
+ assert_defined_action_methods 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'test_engine/tasks#index', 'users#index', 'users#index2', 'users#show'
87
87
  end
88
88
 
89
89
  def test_routed_actions
90
- assert_equal ['posts#index', 'posts#show', 'test_engine/tasks#index'].sort, @traceroute.routed_actions.sort
90
+ assert_routed_actions 'posts#index', 'posts#show', 'test_engine/tasks#index'
91
91
  end
92
92
  end
93
93
  end
@@ -56,7 +56,7 @@ class DotFileTest < Minitest::Test
56
56
  end
57
57
 
58
58
  def test_used_routes_are_ignored
59
- assert_equal ['admin/shops#index', 'api/books#index'].sort, @traceroute.routed_actions.sort
59
+ assert_routed_actions 'admin/shops#index', 'api/books#index'
60
60
  end
61
61
  end
62
62
 
@@ -88,11 +88,11 @@ class EmptyFileTest < Minitest::Test
88
88
  end
89
89
 
90
90
  def test_empty_yaml_file_is_handled_the_same_as_no_file
91
- assert_equal ['users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'].sort, @traceroute.defined_action_methods.sort
91
+ assert_defined_action_methods 'users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'
92
92
  end
93
93
 
94
94
  def test_property_with_no_key
95
- assert_equal ['admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'].sort, @traceroute.routed_actions.sort
95
+ assert_routed_actions 'admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'
96
96
  end
97
97
  end
98
98
 
@@ -127,11 +127,11 @@ class InvalidFileTest < Minitest::Test
127
127
  end
128
128
 
129
129
  def test_empty_yaml_file_is_handled_the_same_as_no_file
130
- assert_equal ['users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'].sort, @traceroute.defined_action_methods.sort
130
+ assert_defined_action_methods 'users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'
131
131
  end
132
132
 
133
133
  def test_property_with_no_key
134
- assert_equal ['admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'].sort, @traceroute.routed_actions.sort
134
+ assert_routed_actions 'admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'
135
135
  end
136
136
  end
137
137
 
@@ -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.7.1'
6
+ s.version = '0.8.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Akira Matsuda']
9
9
  s.email = ['ronnie@dio.jp']
@@ -11,8 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.summary = 'A Rake task that helps you find the dead routes and actions for your Rails 3 app'
12
12
  s.description = "This Rake task investigates the application's routes definition, then tells you unused routes and unreachable action methods"
13
13
 
14
- s.rubyforge_project = 'traceroute'
15
-
16
14
  s.files = `git ls-files`.split("\n")
17
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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.7.1
4
+ version: 0.8.0
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-09-25 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubyforge_project: traceroute
70
- rubygems_version: 2.7.7
69
+ rubyforge_project:
70
+ rubygems_version: 2.7.6
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: A Rake task that helps you find the dead routes and actions for your Rails