rails_export_routes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -12
- data/lib/rails_export_routes.rb +1 -0
- data/lib/rails_export_routes/cli.rb +2 -1
- data/lib/rails_export_routes/formatters/json_pretty.rb +30 -0
- data/lib/rails_export_routes/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29c125a39682f15f553976276b709f76d64ba131677d694034f54dc226b776c
|
4
|
+
data.tar.gz: 4454f83cae0c2723fa7f812f69a5574f948dbe5f752d8a1c9e2617d5886361a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b4b67e680719652cc4fa9494bfeb4bbf53f4545961225c2e4eb8a2f30d33490fe084fce3e9af531a354681d51dcde71ffea403eefdf89a032b92042c826148
|
7
|
+
data.tar.gz: 8e4d9362c99f7da3a14af78955968bacb31e286df4e57dd23fc3f678903f114d83e70dfe7d19c4c3370ef9b27ce59b0cf822ab25f8cb3c1d01868500bfcc3b63
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# rails-export-routes
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a small gem that allows you to export Rails routes to CSV or JSON.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -16,24 +14,35 @@ And then execute:
|
|
16
14
|
|
17
15
|
$ bundle install
|
18
16
|
|
19
|
-
|
17
|
+
## Usage
|
20
18
|
|
21
|
-
|
19
|
+
To export Routes to CSV:
|
22
20
|
|
23
|
-
|
21
|
+
```bash
|
22
|
+
bundle exec rails-export-routes export my-app-routes.csv
|
23
|
+
```
|
24
|
+
|
25
|
+
When JSON is the preferred format:
|
24
26
|
|
25
|
-
|
27
|
+
```bash
|
28
|
+
bundle exec rails-export-routes export --format json my-app-routes.json
|
29
|
+
```
|
30
|
+
|
31
|
+
Pretty JSON:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
bundle exec rails-export-routes export --format json-pretty my-app-routes.json
|
35
|
+
```
|
26
36
|
|
27
37
|
## Development
|
28
38
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
40
|
|
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
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/rails_export_routes/version.rb` and push a new tag.
|
32
42
|
|
33
43
|
## Contributing
|
34
44
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lenon/rails_export_routes.
|
37
46
|
|
38
47
|
## License
|
39
48
|
|
data/lib/rails_export_routes.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rails_export_routes/version'
|
|
4
4
|
require 'rails_export_routes/route_wrapper'
|
5
5
|
require 'rails_export_routes/formatters/csv'
|
6
6
|
require 'rails_export_routes/formatters/json'
|
7
|
+
require 'rails_export_routes/formatters/json_pretty'
|
7
8
|
require 'rails_export_routes/cli'
|
8
9
|
|
9
10
|
module RailsExportRoutes
|
@@ -11,13 +11,14 @@ module RailsExportRoutes
|
|
11
11
|
desc('export FILE', 'export Rails routes to FILE')
|
12
12
|
method_option(:format, type: :string,
|
13
13
|
default: 'csv',
|
14
|
-
enum: %w[csv json])
|
14
|
+
enum: %w[csv json json-pretty])
|
15
15
|
def export(file)
|
16
16
|
load_rails_app(Dir.pwd)
|
17
17
|
|
18
18
|
formatter = case options.fetch(:format)
|
19
19
|
when 'csv' then Formatters::CSV
|
20
20
|
when 'json' then Formatters::JSON
|
21
|
+
when 'json-pretty' then Formatters::JSONPretty
|
21
22
|
end
|
22
23
|
|
23
24
|
formatter.new(wrapped_rails_routes).export_to_file(file)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module RailsExportRoutes
|
6
|
+
module Formatters
|
7
|
+
class JSONPretty
|
8
|
+
def initialize(routes)
|
9
|
+
@routes = routes
|
10
|
+
end
|
11
|
+
|
12
|
+
def export_to_file(file) # rubocop:disable Metrics/MethodLength
|
13
|
+
data = @routes.map do |route|
|
14
|
+
{
|
15
|
+
verb: route.verb,
|
16
|
+
path: route.path_spec,
|
17
|
+
controller: route.controller,
|
18
|
+
action: route.action,
|
19
|
+
name: route.name,
|
20
|
+
constraints: route.constraints.to_h
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
File.open(file, 'wb') do |f|
|
25
|
+
f.write(::JSON.pretty_generate(data))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_export_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lenon Marcel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/rails_export_routes/cli.rb
|
54
54
|
- lib/rails_export_routes/formatters/csv.rb
|
55
55
|
- lib/rails_export_routes/formatters/json.rb
|
56
|
+
- lib/rails_export_routes/formatters/json_pretty.rb
|
56
57
|
- lib/rails_export_routes/route_wrapper.rb
|
57
58
|
- lib/rails_export_routes/version.rb
|
58
59
|
homepage: https://github.com/lenon/rails_export_routes
|