route_checker 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 876992039ca7c0b63bab5385145f9293fbc3ea0e18ee2542b0f35d1313818188
4
+ data.tar.gz: 88dab977946e2bfb28019a822ca6a8bc890a287aabef412a9547db0d5843c490
5
+ SHA512:
6
+ metadata.gz: 445c267205e2583364a82d82e44bc9737f39a843cf38cfa79c2fe301b9a04f74739673331180c925217e6b0fba73d561a30b54f0d1f97bd6f0db24ca3292022e
7
+ data.tar.gz: 3dce3259ebfcbf03601284cbc732b265ab5f9331b0ead33f5e450a8b66e5fc27e6eaba0a189d24efa690aea25f3b3f967544c85aeb9c4976cf3dd9a54e1bad8e
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.2.0] - 2022-01-08
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sanjay.salunkhe@aylanetworks.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in route_checker.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ route_checker (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ parallel (1.21.0)
12
+ parser (3.0.3.2)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.2.0)
17
+ rexml (3.2.5)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.3)
31
+ rubocop (1.24.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.15.1, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.15.1)
41
+ parser (>= 3.0.1.1)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.1.0)
44
+
45
+ PLATFORMS
46
+ x86_64-darwin-19
47
+
48
+ DEPENDENCIES
49
+ rake (~> 13.0)
50
+ route_checker!
51
+ rspec (~> 3.0)
52
+ rubocop (~> 1.7)
53
+
54
+ BUNDLED WITH
55
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 sanjay salunkhe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # RouteChecker
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/route_checker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'route_checker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install route_checker
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/route_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/route_checker/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the RouteChecker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/route_checker/blob/master/CODE_OF_CONDUCT.md).
44
+ # route_checker
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "route_checker"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ class Result
5
+ class << self
6
+ def uninitialized_controllers
7
+ Services::UninitializedControllers.call
8
+ end
9
+
10
+ def unreachable_actions
11
+ Services::UnreachableActions.call
12
+ end
13
+
14
+ def unused_routes
15
+ Services::UnusedRoutes.call
16
+ end
17
+
18
+ def print
19
+ Services::PrintResult.call(
20
+ uninitilzed_contant: Services::UninitializedControllers.call,
21
+ unreachable_actions: Services::UnreachableActions.call,
22
+ unused_actions: Services::UnusedRoutes.call
23
+ )
24
+ end
25
+
26
+ def save_to(location, filename, mode='w+', options = {})
27
+ Services::SaveResultToFile.call(location, filename, mode, options)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ class PrintResult
6
+ class << self
7
+ MAX_MESSAGE_TITLE_WIDTH = 150
8
+
9
+ def call(data)
10
+ print_uninitialized_controllers(data)
11
+ print_unreachable_actions(data)
12
+ print_unused_routes(data)
13
+ end
14
+
15
+ private
16
+
17
+ def print_uninitialized_controllers(data)
18
+ return puts " 0 UNINITIALIZED CONTROLLER'S FOUND. \n" if data[:uninitilzed_contant].empty?
19
+
20
+ puts "\n\n"
21
+ puts " #{data[:uninitilzed_contant].count} UNINITIALIZED CONTROLLER'S: ROUTE IS PRESENT BUT IT'S CONTROLLER IS MISSING ".center(MAX_MESSAGE_TITLE_WIDTH, "=>")
22
+ data[:uninitilzed_contant].each do |data|
23
+ puts "#{data[:verb]} #{data[:route]}, #{"Controller:"} #{data[:controller]} "
24
+ end
25
+ puts " END ".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
26
+ end
27
+
28
+ def print_unreachable_actions(data)
29
+ return puts " 0 UNREACHABLE ACTIONS FOUND. \n" if data[:unreachable_actions].empty?
30
+ procs = []
31
+ counter = 0
32
+ puts "\n\n"
33
+ p = Proc.new{|count| puts " #{count} UNREACHABLE ACTIONS: ACTION IS PRESENT IN CONTROLLER BUT IT'S ROUTE IS MISSING ".center(MAX_MESSAGE_TITLE_WIDTH, "=>") }
34
+ data[:unreachable_actions].each do |key, values|
35
+ values.each do |val|
36
+ counter = counter + 1
37
+ procs.push(Proc.new { puts "#{"Controller:"} #{key}, #{"Action:"} #{val}, #{"Source_Location:"} #{key.constantize.new.method(val).source_location}" })
38
+ end
39
+ end
40
+ p.call(counter)
41
+ procs.each{|p| p.call }
42
+ puts " END ".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
43
+ end
44
+
45
+ def print_unused_routes(data)
46
+ return puts " 0 UNUSED ROUTES FOUND. \n" if data[:unused_actions].try(:empty?)
47
+ puts "\n\n"
48
+ puts " #{data[:unused_actions].count} UNUSED ROUTES: ROUTE IS PRESENT BUT IT'S CONTROLLER'S ACTION IS MISSING ".center(MAX_MESSAGE_TITLE_WIDTH, "=>")
49
+ data[:unused_actions].each do |values|
50
+ puts "#{values[3]} #{values[2]}, #{"Controller:"} #{values[0]}, #{"Action:"} #{values[1]}"
51
+ end
52
+ puts " END ".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ module Reloader
6
+ private
7
+
8
+ def reload_rails_console
9
+ if Gem::Version.new(Rails.version) < Gem::Version.new("5.0.0.beta4")
10
+ # ActionDispatch::Reloader.cleanup!
11
+ # ActionDispatch::Reloader.prepare!
12
+ else
13
+ # ::Rails.application.reloader.reload!
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ class SaveResultToFile
6
+ class InvalidmodeError < StandardError; end
7
+
8
+ class InvalidOptions < StandardError; end
9
+
10
+ class << self
11
+ MAX_MESSAGE_TITLE_WIDTH = 150
12
+
13
+ def call(location, filename, mode, options={})
14
+ File.open(File.join(location, filename), mode) do |f|
15
+ unless valid_mode?(mode)
16
+ f.close
17
+ fail InvalidmodeError, "Invalid file mode specified. only 'a+' and 'w+' file modes are supported"
18
+ end
19
+
20
+ if options.empty?
21
+ save_uninitialized_controllers(f)
22
+ save_unreachable_actions(f)
23
+ save_unused_routes(f)
24
+ else
25
+ unless valid_options?(options)
26
+ f.close
27
+ fail InvalidOptions, "Invalid options specified. expecting hash {:output_only => [<list of options>]}"
28
+ end
29
+ save_uninitialized_controllers(f) if options[:output_only].include?(:uninitialized_constants)
30
+ save_unreachable_actions(f) if options[:output_only].include?(:unreachable_actions)
31
+ save_unused_routes(f) if options[:output_only].include?(:unused_actions)
32
+ end
33
+ f.close
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def valid_mode?(mode)
40
+ ["a+", "w+"].include?(mode)
41
+ end
42
+
43
+ def valid_options?(options)
44
+ options.key?(:output_only) && (options[:output_only] - [:uninitialized_constants, :unreachable_actions,
45
+ :unused_actions]).empty?
46
+ end
47
+
48
+ def save_uninitialized_controllers(file)
49
+ data = Services::UninitializedControllers.call
50
+ return file.puts "0 UNINITIALIZED CONTROLLER'S FOUND.\n".green if data.empty?
51
+
52
+ file.puts "\n\n"
53
+ file.puts "#{data.count} UNINITIALIZED CONTROLLER'S: ROUTE IS PRESENT BUT IT'S CONTROLLER IS MISSING".center(MAX_MESSAGE_TITLE_WIDTH, "=>")
54
+ Services::UninitializedControllers.call.each do |data|
55
+ file.puts "#{data[:verb]} #{data[:route]}, #{"Controller:"} #{data[:controller]} "
56
+ end
57
+ file.puts "END".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
58
+ end
59
+
60
+ def save_unreachable_actions(file)
61
+ data = Services::UnreachableActions.call
62
+ return file.puts "0 UNREACHABLE ACTIONS FOUND.\n".green if data.empty?
63
+ procs = []
64
+ counter = 0
65
+
66
+ file.puts "\n\n"
67
+ p = Proc.new{|count| file.puts "#{count} UNREACHABLE ACTIONS: CONTROLLER'S ACTION IS PRESENT BUT IT'S ROUTE IS MISSING".center(MAX_MESSAGE_TITLE_WIDTH, "=>") }
68
+ data.each do |key, values|
69
+ values.each do |val|
70
+ counter = counter + 1
71
+ procs.push(Proc.new { file.puts "#{"Controller:"} #{key}, #{"Action:"} #{val}, #{"Source_Location:"} #{key.constantize.new.method(val).source_location}" })
72
+ end
73
+ end
74
+ p.call(counter)
75
+ procs.each{|p| p.call }
76
+ file.puts "END".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
77
+ end
78
+
79
+ def save_unused_routes(file)
80
+ data = Services::UnusedRoutes.call
81
+ return file.puts "0 UNUSED ROUTES FOUND.\n".green if data.empty?
82
+
83
+ file.puts "\n\n"
84
+ file.puts "#{data.count} UNUSED ROUTES: ROUTE IS PRESENT BUT IT'S CONTROLLER'S ACTION IS MISSING".center(MAX_MESSAGE_TITLE_WIDTH, "=>")
85
+ data.each do |values|
86
+ file.puts "#{values[3]} #{values[2]}, #{"Controller:"} #{values[0]}, #{"Action:"} #{values[1]}"
87
+ end
88
+ file.puts "END".center(MAX_MESSAGE_TITLE_WIDTH, "<=")
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ class UninitializedControllers
6
+ class << self
7
+ def call
8
+ reload_routes
9
+ uninitialized_controllers_list
10
+ end
11
+
12
+ private
13
+
14
+ def reload_routes
15
+ load File.join(Rails.root.to_s,'/config/routes.rb')
16
+ end
17
+
18
+ def routes
19
+ ::Rails.application.routes.routes.map do |r|
20
+ [r.defaults[:controller], r.defaults[:action], r.path.spec.to_s, r.verb.is_a?(String) ? r.verb : r.verb.source[/[a-z]+/i].to_s] unless r.defaults[:controller].nil?
21
+ end.compact
22
+ end
23
+
24
+ def uninitialized_controllers_list
25
+ routes.each_with_object([]) do |route, uninitilzed_contant|
26
+ next if route[0].nil?
27
+
28
+ controller = begin
29
+ "#{route[0].camelize}Controller".constantize
30
+ rescue StandardError
31
+ nil
32
+ end
33
+ uninitilzed_contant.push({controller: "#{route[0].camelize}Controller", action: route[1], route: route[2], verb: route[3]}) unless controller.present?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ class UnreachableActions
6
+ class << self
7
+ def call
8
+ reload_routes
9
+ require_controllers
10
+ unreachable_actions(controllers_and_actions)
11
+ end
12
+
13
+ private
14
+
15
+ def reload_routes
16
+ load File.join(Rails.root.to_s,'/config/routes.rb')
17
+ end
18
+
19
+ def require_controllers
20
+ Dir[Rails.root.join("app/controllers/**/*_controller.rb")].each { |file| require file }
21
+ end
22
+
23
+ def controllers_and_actions
24
+ Rails.application.routes.routes.each_with_object(Hash.new { [] }) do |r, hash|
25
+
26
+ next if r.defaults[:controller].nil?
27
+
28
+ hash[r.defaults[:controller].camelize.to_s.concat("Controller")] =
29
+ hash[r.defaults[:controller].camelize.to_s.concat("Controller")].concat([r.defaults[:action].to_sym])
30
+ end
31
+ end
32
+
33
+ def unreachable_actions(all_controllers_and_actions)
34
+ ApplicationController.descendants.each_with_object(Hash.new { [] }) do |controller, unreachable_actions_list|
35
+ result = (controller.instance_methods(false) - all_controllers_and_actions[controller.to_s])
36
+ unless result.empty?
37
+ result.each do |action|
38
+ unreachable_actions_list[controller.to_s] = unreachable_actions_list[controller.to_s].push(action) unless action.to_s.starts_with?("_")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ module Services
5
+ class UnusedRoutes
6
+ class << self
7
+ include RouteChecker::Services::Reloader
8
+ def call
9
+ reload_routes
10
+ routes.each_with_object([]) do |route, unused_routes|
11
+ next if route[0].nil?
12
+
13
+ controller = begin
14
+ "#{route[0].camelize}Controller".constantize
15
+ rescue StandardError
16
+ next
17
+ end
18
+
19
+ unless controller.instance_methods.include?(route[1].to_sym)
20
+ unused_routes.push(route)
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def reload_routes
28
+ load File.join(Rails.root.to_s,'/config/routes.rb')
29
+ end
30
+
31
+ def routes
32
+ ::Rails.application.routes.routes.map do |r|
33
+ [r.defaults[:controller], r.defaults[:action], r.path.spec.to_s, r.verb.is_a?(String) ? r.verb : r.verb.source[/[a-z]+/i].to_s] unless r.defaults[:controller].nil?
34
+ end.compact
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouteChecker
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "route_checker/version"
4
+ require_relative "route_checker/services/reloader"
5
+ require_relative "route_checker/result"
6
+ require_relative "route_checker/services/print_result"
7
+ require_relative "route_checker/services/save_result_to_file"
8
+ require_relative "route_checker/services/unreachable_actions"
9
+ require_relative "route_checker/services/unused_routes"
10
+ require_relative "route_checker/services/uninitialized_controllers"
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/route_checker/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "route_checker"
7
+ spec.version = RouteChecker::VERSION
8
+ spec.authors = ["sanjay salunkhe"]
9
+ spec.email = ["sanjay.salunkhe@aylanetworks.com"]
10
+
11
+ spec.summary = "Write a short summary, because RubyGems requires one."
12
+ spec.description = "route checker gem helps to find unused routes and unreachable actions in rails application."
13
+ spec.homepage = "https://github.com/sanjay-salunkhe/route_checker"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/sanjay-salunkhe/route_checker"
21
+ spec.metadata["changelog_uri"] = "https://github.com/sanjay-salunkhe/route_checker/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "xyz", "x.x.x"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: route_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - sanjay salunkhe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: route checker gem helps to find unused routes and unreachable actions
14
+ in rails application.
15
+ email:
16
+ - sanjay.salunkhe@aylanetworks.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - lib/route_checker.rb
35
+ - lib/route_checker/result.rb
36
+ - lib/route_checker/services/print_result.rb
37
+ - lib/route_checker/services/reloader.rb
38
+ - lib/route_checker/services/save_result_to_file.rb
39
+ - lib/route_checker/services/uninitialized_controllers.rb
40
+ - lib/route_checker/services/unreachable_actions.rb
41
+ - lib/route_checker/services/unused_routes.rb
42
+ - lib/route_checker/version.rb
43
+ - route_checker.gemspec
44
+ homepage: https://github.com/sanjay-salunkhe/route_checker
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ allowed_push_host: https://rubygems.org
49
+ homepage_uri: https://github.com/sanjay-salunkhe/route_checker
50
+ source_code_uri: https://github.com/sanjay-salunkhe/route_checker
51
+ changelog_uri: https://github.com/sanjay-salunkhe/route_checker/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.3
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.2.15
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Write a short summary, because RubyGems requires one.
71
+ test_files: []