pry-rails-diff-routes 0.3.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 +7 -0
- data/.github/workflows/build-test.yml +26 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +40 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/images/demo-screenshot.gif +0 -0
- data/lib/pry-rails-diff-routes.rb +7 -0
- data/lib/pry_rails_diff_routes/commands.rb +7 -0
- data/lib/pry_rails_diff_routes/commands/diff_routes.rb +91 -0
- data/lib/pry_rails_diff_routes/formatters/modified_routes_formatter.rb +73 -0
- data/lib/pry_rails_diff_routes/formatters/new_routes_formatter.rb +14 -0
- data/lib/pry_rails_diff_routes/formatters/removed_routes_formatter.rb +14 -0
- data/lib/pry_rails_diff_routes/modern_hash_format.rb +8 -0
- data/lib/pry_rails_diff_routes/railtie.rb +21 -0
- data/lib/pry_rails_diff_routes/route_wrapper.rb +58 -0
- data/lib/pry_rails_diff_routes/routes_diff_processor.rb +72 -0
- data/lib/pry_rails_diff_routes/util.rb +45 -0
- data/lib/pry_rails_diff_routes/version.rb +3 -0
- data/pry-rails-diff-routes.gemspec +27 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9c0bb050f77707fc2a2a579fe4582a629c7e9d4030ffd3d0d3928b362eeb0c3
|
4
|
+
data.tar.gz: 8e0135ae1553435c42d702af36d0389ff5e7b2604039903dc885d91ef4615779
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0b3a2a2c9d63782a81368585ab3c176b65822b359f8087cd0fca702a6c93dafc4651681c82813b7aaee1595c224d2435f5e6270900ee50b36ab81e203e0aebf
|
7
|
+
data.tar.gz: cdc1794f7ade7a1dfb42b4d705559f42adbe1812a1dac0ad04d4367a1cdcae0bfa70c2a18351731781fb67d6696c6d7dd9800b203977e5529c97682daa6751ee
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: build-test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu-latest, macos-latest]
|
15
|
+
ruby: [2.5, 2.6, 2.7, jruby]
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Build and test with Rake
|
23
|
+
run: |
|
24
|
+
gem install bundler
|
25
|
+
bundle install --jobs 4 --retry 3
|
26
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## [Unreleased]
|
5
|
+
|
6
|
+
## [0.3.0] - 2020-12-12
|
7
|
+
### Changed
|
8
|
+
- Gem name
|
9
|
+
|
10
|
+
|
11
|
+
## [0.2.0] - 2020-12-12
|
12
|
+
### Changed
|
13
|
+
- Highlight red and green text style and color
|
14
|
+
- Pry version for dependency resolution
|
15
|
+
|
16
|
+
|
17
|
+
## [0.1.1] - 2020-03-25
|
18
|
+
### Added
|
19
|
+
- Testing status badge
|
20
|
+
- Github action for testing workflow
|
21
|
+
- Demo screenshot to readme
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
- Constraints indentation on modified routes formatting
|
25
|
+
- Modern hash format on modified routes formatting
|
26
|
+
|
27
|
+
|
28
|
+
## [0.1.0] - 2020-03-21
|
29
|
+
### Added
|
30
|
+
- `diff-routes --removed`
|
31
|
+
- `diff-routes --modified`
|
32
|
+
- `diff-routes --new`
|
33
|
+
- `diff-routes --save`
|
34
|
+
|
35
|
+
|
36
|
+
[Unreleased]: https://github.com/styd/diff-routes/compare/v0.3.0...HEAD
|
37
|
+
[0.3.0]: https://github.com/styd/diff-routes/compare/v0.2.0...v0.3.0
|
38
|
+
[0.2.0]: https://github.com/styd/diff-routes/compare/v0.1.1...v0.2.0
|
39
|
+
[0.1.1]: https://github.com/styd/diff-routes/compare/v0.1.0...v0.1.1
|
40
|
+
[0.1.0]: https://github.com/styd/diff-routes/releases/tag/v0.1.0
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at a.styd@yahoo.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Adrian Setyadi
|
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,82 @@
|
|
1
|
+
# DiffRoutes 
|
2
|
+
|
3
|
+
> Inspect routes changes in Rails console.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pry-rails-diff-routes', group: :development
|
11
|
+
```
|
12
|
+
|
13
|
+
DiffRoutes will set Pry as the REPL in your Rails console, just like when you use PryRails.
|
14
|
+
|
15
|
+
If you already used PryRails, you should install DiffRoutes after it.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'pry-rails' # not a dependency
|
19
|
+
gem 'pry-rails-diff-routes'
|
20
|
+
```
|
21
|
+
|
22
|
+
When you type `help` in Rails console, you'll notice that `diff-routes` is listed in the same
|
23
|
+
group as PryRails commands.
|
24
|
+
|
25
|
+
```
|
26
|
+
Rails
|
27
|
+
diff-routes Show the difference you made in routes.
|
28
|
+
find-route See which urls match a given controller.
|
29
|
+
recognize-path See which route matches a url.
|
30
|
+
show-middleware Show all middleware (that rails knows about).
|
31
|
+
show-model Show the given model.
|
32
|
+
show-models Show all models.
|
33
|
+
show-routes Show all routes in match order.
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
### Flags
|
38
|
+
|
39
|
+
A route is considered the same route if it maintains its verb (http method, e.g. `GET`, `POST`,
|
40
|
+
etc.) and uri path. When its other properties are changed, we call it a modified route.
|
41
|
+
|
42
|
+
#### `-R` or `--removed`
|
43
|
+
|
44
|
+
Show removed routes only.
|
45
|
+
|
46
|
+
#### `-M` or `--modified`
|
47
|
+
|
48
|
+
Show modified routes only.
|
49
|
+
|
50
|
+
#### `-N` or `--new`
|
51
|
+
|
52
|
+
Show new routes only.
|
53
|
+
|
54
|
+
#### `-S` or `--save`
|
55
|
+
|
56
|
+
Make current routes as the basis for changes.
|
57
|
+
|
58
|
+
You can combine `-R`, `-M`, and `-N` together, but not `-S`.
|
59
|
+
|
60
|
+
### Demo Screenshot
|
61
|
+
|
62
|
+

|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at
|
67
|
+
https://github.com/styd/diff-routes.
|
68
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are
|
69
|
+
expected to adhere to the
|
70
|
+
[code of conduct](https://github.com/styd/diff-routes/blob/master/CODE_OF_CONDUCT.md).
|
71
|
+
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the
|
76
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
77
|
+
|
78
|
+
## Code of Conduct
|
79
|
+
|
80
|
+
Everyone interacting in the DiffRoutes project's codebases, issue trackers, chat rooms
|
81
|
+
and mailing lists is expected to follow the
|
82
|
+
[code of conduct](https://github.com/styd/routes/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pry/diff/routes"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
Binary file
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../route_wrapper'
|
2
|
+
|
3
|
+
module PryRailsDiffRoutes
|
4
|
+
class DiffRoutes < Pry::ClassCommand
|
5
|
+
R_MODE = 1; M_MODE = 2; N_MODE = 4; A_MODE = 7
|
6
|
+
|
7
|
+
singleton_class.attr_accessor :_previous_routes
|
8
|
+
|
9
|
+
match 'diff-routes'
|
10
|
+
group 'Rails'
|
11
|
+
description 'Show the difference you made in routes.'
|
12
|
+
banner <<-BANNER
|
13
|
+
Usage: diff-routes [-S|-R|-M|-N]
|
14
|
+
|
15
|
+
`diff-routes' displays changes in routes.
|
16
|
+
|
17
|
+
# Save current routes as the basis for changes
|
18
|
+
diff-routes -S
|
19
|
+
|
20
|
+
# Display routes that have been removed
|
21
|
+
diff-routes -R
|
22
|
+
|
23
|
+
# Display modified routes
|
24
|
+
diff-routes -M
|
25
|
+
|
26
|
+
# Display new routes
|
27
|
+
diff-routes -N
|
28
|
+
BANNER
|
29
|
+
|
30
|
+
def options(opt)
|
31
|
+
opt.on :S, "save", "Save current routes",
|
32
|
+
as: String
|
33
|
+
opt.on :R, "removed", "Show removed routes",
|
34
|
+
as: String
|
35
|
+
opt.on :M, "modified", "Show modified routes",
|
36
|
+
as: String
|
37
|
+
opt.on :N, "new", "Show new routes",
|
38
|
+
as: String
|
39
|
+
end
|
40
|
+
|
41
|
+
def process
|
42
|
+
Rails.application.reload_routes!
|
43
|
+
all_routes = Rails.application.routes.routes
|
44
|
+
|
45
|
+
return save_routes(all_routes) if opts[:S]
|
46
|
+
|
47
|
+
removed_mode = opts[:R] ? R_MODE : 0
|
48
|
+
modified_mode = opts[:M] ? M_MODE : 0
|
49
|
+
new_mode = opts[:N] ? N_MODE : 0
|
50
|
+
display_mode = removed_mode | modified_mode | new_mode
|
51
|
+
|
52
|
+
output.puts process_diff(all_routes, display_mode)
|
53
|
+
end
|
54
|
+
|
55
|
+
# `opts[:S]`.
|
56
|
+
def save_routes(routes)
|
57
|
+
DiffRoutes._previous_routes = wrap_routes(routes)
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def wrap_routes(routes)
|
62
|
+
prev_name = nil
|
63
|
+
routes.reject(&:internal).map do |route|
|
64
|
+
if route.name.nil?
|
65
|
+
route.instance_variable_set(:@name, prev_name)
|
66
|
+
else
|
67
|
+
prev_name = route.name
|
68
|
+
end
|
69
|
+
|
70
|
+
RouteWrapper.new(route)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def process_diff(current_routes, mode)
|
75
|
+
routes =
|
76
|
+
RoutesDiffProcessor.new(
|
77
|
+
DiffRoutes._previous_routes,
|
78
|
+
wrap_routes(current_routes),
|
79
|
+
mode
|
80
|
+
)
|
81
|
+
|
82
|
+
if routes.changed?
|
83
|
+
routes
|
84
|
+
else
|
85
|
+
"No routes changed."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
Commands.add_command(self)
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module PryRailsDiffRoutes
|
2
|
+
class ModifiedRoutesFormatter
|
3
|
+
include Util
|
4
|
+
|
5
|
+
def initialize(routes_changes)
|
6
|
+
@routes_changes = routes_changes
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
<<~MODIFIED
|
11
|
+
#{bold_yellow 'Modified:'}
|
12
|
+
#{routes_diff}
|
13
|
+
MODIFIED
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def routes_diff
|
18
|
+
@routes_changes.map do |before, after|
|
19
|
+
<<~CHANGES
|
20
|
+
#{before.display_verb_and_path}
|
21
|
+
#{prefix_changes(before, after)}
|
22
|
+
#{controller_changes(before, after)}
|
23
|
+
#{action_changes(before, after)}
|
24
|
+
#{constraints_changes(before, after)}
|
25
|
+
CHANGES
|
26
|
+
end.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
def prefix_changes(before, after)
|
30
|
+
if before.prefix != after.prefix
|
31
|
+
pad_lines <<~DIFF.chomp, 2
|
32
|
+
#{arrow_key('Prefix')}-#{highlight_red before.prefix}
|
33
|
+
+#{highlight_green after.prefix}
|
34
|
+
DIFF
|
35
|
+
else
|
36
|
+
pad_lines before.display_prefix, 2
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def controller_changes(before, after)
|
41
|
+
if before.controller != after.controller
|
42
|
+
pad_lines <<~DIFF.chomp, 2
|
43
|
+
#{arrow_key('Controller')}-#{highlight_red(before.controller.camelize + 'Controller')}
|
44
|
+
+#{highlight_green(after.controller.camelize + 'Controller')}
|
45
|
+
DIFF
|
46
|
+
else
|
47
|
+
pad_lines before.display_controller, 2
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def action_changes(before, after)
|
52
|
+
if before.action != after.action
|
53
|
+
pad_lines <<~DIFF.chomp, 2
|
54
|
+
#{arrow_key('Action')}-#{highlight_red('#' + before.action)}
|
55
|
+
+#{highlight_green('#' + after.action)}
|
56
|
+
DIFF
|
57
|
+
else
|
58
|
+
pad_lines before.display_action, 2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def constraints_changes(before, after)
|
63
|
+
if before.constraints != after.constraints
|
64
|
+
pad_lines <<~DIFF.chomp, 2
|
65
|
+
#{arrow_key('Constraints')}-#{highlight_red before.constraints}
|
66
|
+
+#{highlight_green after.constraints}
|
67
|
+
DIFF
|
68
|
+
else
|
69
|
+
pad_lines before.display_constraints, 2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PryRailsDiffRoutes
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
# Cribbed from PryRails::Railtie
|
4
|
+
# Removed Rails versions < 5 checking as they are no longer supported.
|
5
|
+
console do
|
6
|
+
unless defined? PryRails
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
Rails.application.config.console = Pry
|
10
|
+
|
11
|
+
require "rails/console/app"
|
12
|
+
require "rails/console/helpers"
|
13
|
+
TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'pry_rails_diff_routes/commands'
|
17
|
+
|
18
|
+
DiffRoutes.new.save_routes(Rails.application.routes.routes)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'action_dispatch/routing/inspector'
|
2
|
+
require_relative 'util'
|
3
|
+
require_relative 'modern_hash_format'
|
4
|
+
|
5
|
+
module PryRailsDiffRoutes
|
6
|
+
class RouteWrapper < ActionDispatch::Routing::RouteWrapper
|
7
|
+
using ModernHashFormat if RUBY_ENGINE == 'ruby'
|
8
|
+
|
9
|
+
include Util
|
10
|
+
include Comparable
|
11
|
+
|
12
|
+
alias_method :prefix, :name
|
13
|
+
|
14
|
+
def <=>(other)
|
15
|
+
self.prefix <=> other.prefix &&
|
16
|
+
self.verb <=> other.verb &&
|
17
|
+
self.reqs <=> other.reqs
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash
|
21
|
+
[self.prefix, self.verb, self.reqs].hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def eql?(other)
|
25
|
+
self == other
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
pad_lines <<~ROUTE, 1
|
30
|
+
#{display_verb_and_path}
|
31
|
+
#{display_prefix}
|
32
|
+
#{display_controller}
|
33
|
+
#{display_action}
|
34
|
+
#{display_constraints}
|
35
|
+
ROUTE
|
36
|
+
end
|
37
|
+
|
38
|
+
def display_verb_and_path
|
39
|
+
"#{bold verb.ljust(6, ' ')} #{dim_format path}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def display_prefix
|
43
|
+
"#{arrow_key('Prefix')} #{prefix}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def display_controller
|
47
|
+
"#{arrow_key('Controller')} #{controller.camelize}Controller"
|
48
|
+
end
|
49
|
+
|
50
|
+
def display_action
|
51
|
+
"#{arrow_key('Action')} ##{action}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def display_constraints
|
55
|
+
"#{arrow_key('Constraints')} #{constraints}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative 'formatters/removed_routes_formatter'
|
2
|
+
require_relative 'formatters/modified_routes_formatter'
|
3
|
+
require_relative 'formatters/new_routes_formatter'
|
4
|
+
|
5
|
+
module PryRailsDiffRoutes
|
6
|
+
class RoutesDiffProcessor
|
7
|
+
def initialize(previous_routes, current_routes, display_mode)
|
8
|
+
@previous = previous_routes
|
9
|
+
@current = current_routes
|
10
|
+
@mode = display_mode.zero? ? DiffRoutes::A_MODE : display_mode
|
11
|
+
|
12
|
+
@removed, @modified, @new = process_diff if changed?
|
13
|
+
end
|
14
|
+
|
15
|
+
def changed?
|
16
|
+
@previous != @current
|
17
|
+
end
|
18
|
+
|
19
|
+
def process_diff
|
20
|
+
inner_join = @previous & @current
|
21
|
+
removed_routes = @previous - inner_join
|
22
|
+
new_routes = @current - inner_join
|
23
|
+
|
24
|
+
modified_routes = {}
|
25
|
+
|
26
|
+
removed_routes.reject! do |r_route|
|
27
|
+
catch :modified do
|
28
|
+
new_routes.each do |n_route|
|
29
|
+
if n_route.verb == r_route.verb && n_route.path == r_route.path
|
30
|
+
modified_routes[r_route] = n_route
|
31
|
+
new_routes.reject!{|route| route == n_route }
|
32
|
+
|
33
|
+
throw :modified, true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
[removed_routes, modified_routes, new_routes]
|
42
|
+
end
|
43
|
+
|
44
|
+
def show_removed?
|
45
|
+
(@mode & DiffRoutes::R_MODE == DiffRoutes::R_MODE) && @removed.any?
|
46
|
+
end
|
47
|
+
|
48
|
+
def display_removed
|
49
|
+
RemovedRoutesFormatter.new(@removed) if show_removed?
|
50
|
+
end
|
51
|
+
|
52
|
+
def show_modified?
|
53
|
+
(@mode & DiffRoutes::M_MODE == DiffRoutes::M_MODE) && @modified.any?
|
54
|
+
end
|
55
|
+
|
56
|
+
def display_modified
|
57
|
+
ModifiedRoutesFormatter.new(@modified) if show_modified?
|
58
|
+
end
|
59
|
+
|
60
|
+
def show_new?
|
61
|
+
(@mode & DiffRoutes::N_MODE == DiffRoutes::N_MODE) && @new.any?
|
62
|
+
end
|
63
|
+
|
64
|
+
def display_new
|
65
|
+
NewRoutesFormatter.new(@new) if show_new?
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_s
|
69
|
+
"#{display_removed}#{display_modified}#{display_new}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'modern_hash_format'
|
2
|
+
|
3
|
+
module PryRailsDiffRoutes
|
4
|
+
module Util
|
5
|
+
using ModernHashFormat if RUBY_ENGINE == 'ruby'
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def pad_lines(text="", pad_length=0)
|
10
|
+
text.gsub(/^(.*)$/, ' ' * 2 * pad_length + "\\1")
|
11
|
+
end
|
12
|
+
|
13
|
+
def arrow_key(key)
|
14
|
+
key.ljust(12, ' ') + '->'
|
15
|
+
end
|
16
|
+
|
17
|
+
def dim_format(text)
|
18
|
+
text.sub(/(\(.:format\))$/, "\e[2m\\1\e[0m")
|
19
|
+
end
|
20
|
+
|
21
|
+
def highlight_red(text)
|
22
|
+
"\e[1;41m#{text}\e[0m"
|
23
|
+
end
|
24
|
+
|
25
|
+
def highlight_green(text)
|
26
|
+
"\e[1;42m#{text}\e[0m"
|
27
|
+
end
|
28
|
+
|
29
|
+
def bold(text)
|
30
|
+
"\e[1m#{text}\e[0m"
|
31
|
+
end
|
32
|
+
|
33
|
+
def bold_red(text)
|
34
|
+
"\e[1;31m#{text}\e[0m"
|
35
|
+
end
|
36
|
+
|
37
|
+
def bold_yellow(text)
|
38
|
+
"\e[1;33m#{text}\e[0m"
|
39
|
+
end
|
40
|
+
|
41
|
+
def bold_green(text)
|
42
|
+
"\e[1;32m#{text}\e[0m"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/pry_rails_diff_routes/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "pry-rails-diff-routes"
|
5
|
+
spec.version = PryRailsDiffRoutes::VERSION
|
6
|
+
spec.authors = ["Adrian Setyadi"]
|
7
|
+
spec.email = ["a.styd@yahoo.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Inspect routes changes in Rails console}
|
10
|
+
spec.description = %q{A Pry plugin to see the difference you made to Rails routes}
|
11
|
+
spec.homepage = "https://github.com/styd/diff-routes"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
19
|
+
end
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "pry", ">= 0.12"
|
23
|
+
|
24
|
+
spec.add_development_dependency "rails", ">= 5"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-rails-diff-routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Setyadi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: A Pry plugin to see the difference you made to Rails routes
|
70
|
+
email:
|
71
|
+
- a.styd@yahoo.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".github/workflows/build-test.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- images/demo-screenshot.gif
|
88
|
+
- lib/pry-rails-diff-routes.rb
|
89
|
+
- lib/pry_rails_diff_routes/commands.rb
|
90
|
+
- lib/pry_rails_diff_routes/commands/diff_routes.rb
|
91
|
+
- lib/pry_rails_diff_routes/formatters/modified_routes_formatter.rb
|
92
|
+
- lib/pry_rails_diff_routes/formatters/new_routes_formatter.rb
|
93
|
+
- lib/pry_rails_diff_routes/formatters/removed_routes_formatter.rb
|
94
|
+
- lib/pry_rails_diff_routes/modern_hash_format.rb
|
95
|
+
- lib/pry_rails_diff_routes/railtie.rb
|
96
|
+
- lib/pry_rails_diff_routes/route_wrapper.rb
|
97
|
+
- lib/pry_rails_diff_routes/routes_diff_processor.rb
|
98
|
+
- lib/pry_rails_diff_routes/util.rb
|
99
|
+
- lib/pry_rails_diff_routes/version.rb
|
100
|
+
- pry-rails-diff-routes.gemspec
|
101
|
+
homepage: https://github.com/styd/diff-routes
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.4.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.0.3
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Inspect routes changes in Rails console
|
124
|
+
test_files: []
|