better_routes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +95 -0
- data/Rakefile +33 -0
- data/lib/better_routes.rb +4 -0
- data/lib/better_routes/formatter.rb +3 -0
- data/lib/better_routes/formatter/csv_formatter.rb +38 -0
- data/lib/better_routes/formatter/markdown_formatter.rb +39 -0
- data/lib/better_routes/formatter/tsv_formatter.rb +38 -0
- data/lib/better_routes/railtie.rb +7 -0
- data/lib/better_routes/version.rb +3 -0
- data/lib/tasks.rb +1 -0
- data/lib/tasks/better_routes_tasks.rake +38 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 60732ea58a9817c84477c8d32e6451e311f278434ee1ef1c77e5cdd8c05ba328
|
4
|
+
data.tar.gz: becf64bc8fd1636834454d81976e0bd65ae2758a1bc3142e6f4e1304e3d08ad6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d42dcc609245c12a7f914dc6ea9115cd66322637aec4d2cb3dff4085acb9dc23b0202c2621dffce0b4f23909a253e22847cf407a5711ef57231ab328c07af24f
|
7
|
+
data.tar.gz: 7b9c81db8ca0f63425339b9aa1250957d859cb01032ac228759a750c0ccd3297796cd2c730a664aface7fe6c3bf5d2824ce97e79579a17f44cad82d3886ba3d8
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 msroz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# 🖌 BetterRoutes
|
2
|
+
|
3
|
+
Print rials routes with various formats.
|
4
|
+
It is easy way to copy and paste on Spreadsheet, GitHub and so on :)
|
5
|
+
|
6
|
+
## 🤲 Usage
|
7
|
+
|
8
|
+
```bash
|
9
|
+
$ rake better_routes
|
10
|
+
```
|
11
|
+
|
12
|
+
## 📐 Formats
|
13
|
+
|
14
|
+
### Sample routes file
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# config/routes.rb
|
18
|
+
Rails.application.routes.draw do
|
19
|
+
resources :entries
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
### TSV (Tab Separated Values)
|
24
|
+
|
25
|
+
```bash
|
26
|
+
# (default)
|
27
|
+
$ FORMAT=tsv rake better_routes
|
28
|
+
|
29
|
+
Prefix, Verb, URI Pattern, Controller#Action
|
30
|
+
entries GET /entries(.:format) entries#index
|
31
|
+
POST /entries(.:format) entries#create
|
32
|
+
new_entry GET /entries/new(.:format) entries#new
|
33
|
+
edit_entry GET /entries/:id/edit(.:format) entries#edit
|
34
|
+
entry GET /entries/:id(.:format) entries#show
|
35
|
+
PATCH /entries/:id(.:format) entries#update
|
36
|
+
PUT /entries/:id(.:format) entries#update
|
37
|
+
DELETE /entries/:id(.:format) entries#destroy
|
38
|
+
```
|
39
|
+
|
40
|
+
### CSV (Comma Separated Values)
|
41
|
+
|
42
|
+
```bash
|
43
|
+
$ FORMAT=csv rake better_routes
|
44
|
+
Prefix, Verb, URI Pattern, Controller#Action
|
45
|
+
entries,GET,/entries(.:format),entries#index
|
46
|
+
,POST,/entries(.:format),entries#create
|
47
|
+
new_entry,GET,/entries/new(.:format),entries#new
|
48
|
+
edit_entry,GET,/entries/:id/edit(.:format),entries#edit
|
49
|
+
entry,GET,/entries/:id(.:format),entries#show
|
50
|
+
,PATCH,/entries/:id(.:format),entries#update
|
51
|
+
,PUT,/entries/:id(.:format),entries#update
|
52
|
+
,DELETE,/entries/:id(.:format),entries#destroy
|
53
|
+
```
|
54
|
+
|
55
|
+
### Markdown Table
|
56
|
+
|
57
|
+
```bash
|
58
|
+
$ FORMAT=markdown rake better_routes
|
59
|
+
|Prefix|Verb|URI Pattern|Controller#Action|
|
60
|
+
|------|----|-----------|-----------------|
|
61
|
+
|entries|GET|/entries(.:format)|entries#index|
|
62
|
+
||POST|/entries(.:format)|entries#create|
|
63
|
+
|new_entry|GET|/entries/new(.:format)|entries#new|
|
64
|
+
|edit_entry|GET|/entries/:id/edit(.:format)|entries#edit|
|
65
|
+
|entry|GET|/entries/:id(.:format)|entries#show|
|
66
|
+
||PATCH|/entries/:id(.:format)|entries#update|
|
67
|
+
||PUT|/entries/:id(.:format)|entries#update|
|
68
|
+
||DELETE|/entries/:id(.:format)|entries#destroy|
|
69
|
+
```
|
70
|
+
|
71
|
+
## 🤝 Installation
|
72
|
+
|
73
|
+
Add this line to your application's Gemfile:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
gem 'better_routes'
|
77
|
+
```
|
78
|
+
|
79
|
+
And then execute:
|
80
|
+
```bash
|
81
|
+
$ bundle
|
82
|
+
```
|
83
|
+
|
84
|
+
Or install it yourself as:
|
85
|
+
```bash
|
86
|
+
$ gem install better_routes
|
87
|
+
```
|
88
|
+
|
89
|
+
## 👍 Contributing
|
90
|
+
|
91
|
+
Contribution directions go here.
|
92
|
+
|
93
|
+
## 👉 License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BetterRoutes'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module BetterRoutes
|
2
|
+
module Formatter
|
3
|
+
class CsvFormatter
|
4
|
+
def initialize
|
5
|
+
@buffer = []
|
6
|
+
@current_section = "Application"
|
7
|
+
end
|
8
|
+
|
9
|
+
def result
|
10
|
+
@buffer.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
def section_title(title)
|
14
|
+
@current_section = title
|
15
|
+
end
|
16
|
+
|
17
|
+
def section(routes)
|
18
|
+
@buffer << routes.map do |r|
|
19
|
+
"#{r[:name]},#{r[:verb]},#{r[:path]},#{r[:reqs]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def header(routes)
|
24
|
+
@buffer << "Prefix, Verb, URI Pattern, Controller#Action"
|
25
|
+
end
|
26
|
+
|
27
|
+
if Rails.version > '4.2.11'
|
28
|
+
def no_routes(routes)
|
29
|
+
@buffer << ""
|
30
|
+
end
|
31
|
+
else
|
32
|
+
def no_routes
|
33
|
+
@buffer << ""
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module BetterRoutes
|
2
|
+
module Formatter
|
3
|
+
class MarkdownFormatter
|
4
|
+
def initialize
|
5
|
+
@buffer = []
|
6
|
+
@current_section = "Application"
|
7
|
+
end
|
8
|
+
|
9
|
+
def result
|
10
|
+
@buffer.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
def section_title(title)
|
14
|
+
@current_section = title
|
15
|
+
end
|
16
|
+
|
17
|
+
def section(routes)
|
18
|
+
@buffer << routes.map do |r|
|
19
|
+
"|#{r[:name]}|#{r[:verb]}|#{r[:path]}|#{r[:reqs]}|"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def header(routes)
|
24
|
+
@buffer << "|Prefix|Verb|URI Pattern|Controller#Action|"
|
25
|
+
@buffer << "|------|----|-----------|-----------------|"
|
26
|
+
end
|
27
|
+
|
28
|
+
if Rails.version > '4.2.11'
|
29
|
+
def no_routes(routes)
|
30
|
+
@buffer << ""
|
31
|
+
end
|
32
|
+
else
|
33
|
+
def no_routes
|
34
|
+
@buffer << ""
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module BetterRoutes
|
2
|
+
module Formatter
|
3
|
+
class TsvFormatter
|
4
|
+
def initialize
|
5
|
+
@buffer = []
|
6
|
+
@current_section = "Application"
|
7
|
+
end
|
8
|
+
|
9
|
+
def result
|
10
|
+
@buffer.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
def section_title(title)
|
14
|
+
@current_section = title
|
15
|
+
end
|
16
|
+
|
17
|
+
def section(routes)
|
18
|
+
@buffer << routes.map do |r|
|
19
|
+
"#{r[:name]}\t#{r[:verb]}\t#{r[:path]}\t#{r[:reqs]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def header(routes)
|
24
|
+
@buffer << "Prefix, Verb, URI Pattern, Controller#Action"
|
25
|
+
end
|
26
|
+
|
27
|
+
if Rails.version > '4.2.11'
|
28
|
+
def no_routes(routes)
|
29
|
+
@buffer << ""
|
30
|
+
end
|
31
|
+
else
|
32
|
+
def no_routes
|
33
|
+
@buffer << ""
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load 'tasks/better_routes_tasks.rake'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../better_routes/formatter'
|
2
|
+
|
3
|
+
desc "custom_routes"
|
4
|
+
task better_routes: :environment do
|
5
|
+
|
6
|
+
all_routes = Rails.application.routes.routes
|
7
|
+
require 'action_dispatch/routing/inspector'
|
8
|
+
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
9
|
+
|
10
|
+
routes_filter = nil
|
11
|
+
format = ENV['FORMAT'] || 'tsv'
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: rails better_routes [options]"
|
15
|
+
|
16
|
+
Rake.application.standard_rake_options.each { |args| opts.on(*args) }
|
17
|
+
|
18
|
+
# opts.on("-F FORMAT") do |format|
|
19
|
+
# format = format
|
20
|
+
# end
|
21
|
+
|
22
|
+
opts.on("-c CONTROLLER") do |controller|
|
23
|
+
routes_filter = { controller: controller }
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-g PATTERN") do |pattern|
|
27
|
+
routes_filter = pattern
|
28
|
+
end
|
29
|
+
end.parse!(ARGV.reject { |x| x == "routes" })
|
30
|
+
|
31
|
+
formatter_klass = "BetterRoutes::Formatter::#{format.titleize}Formatter".safe_constantize
|
32
|
+
if formatter_klass.nil?
|
33
|
+
STDERR.puts "format must be one of csv, markdown and tsv(default). got: #{format}"
|
34
|
+
end
|
35
|
+
STDOUT.puts inspector.format(formatter_klass.new, routes_filter)
|
36
|
+
|
37
|
+
exit 0
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: better_routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- msroz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
55
|
+
description: Print rails routes with formats for development;)
|
56
|
+
email:
|
57
|
+
- masaru95__at__gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/better_routes.rb
|
66
|
+
- lib/better_routes/formatter.rb
|
67
|
+
- lib/better_routes/formatter/csv_formatter.rb
|
68
|
+
- lib/better_routes/formatter/markdown_formatter.rb
|
69
|
+
- lib/better_routes/formatter/tsv_formatter.rb
|
70
|
+
- lib/better_routes/railtie.rb
|
71
|
+
- lib/better_routes/version.rb
|
72
|
+
- lib/tasks.rb
|
73
|
+
- lib/tasks/better_routes_tasks.rake
|
74
|
+
homepage: https://github.com/msroz/better_routes
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Print rails routes with formats for development;)
|
97
|
+
test_files: []
|