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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3b758249798b4db8f7d467d746f2270d09337adf7af6ae9dfb8812bad1ec477
4
- data.tar.gz: f26b25d605c5be2a2a81637707bfbe9aa001d1ed1f6bca85ee592f247d6d4ee6
3
+ metadata.gz: d29c125a39682f15f553976276b709f76d64ba131677d694034f54dc226b776c
4
+ data.tar.gz: 4454f83cae0c2723fa7f812f69a5574f948dbe5f752d8a1c9e2617d5886361a3
5
5
  SHA512:
6
- metadata.gz: 48c7fbf70092b376cfbc7fd9bf44fe1e1c9d00a37ca7539b84f16085213df1988a52ff16821d9bf26c191c760771e770fc8815f6b685ef7e8f8bb1ea8cca96d9
7
- data.tar.gz: 0b3c91f1d12409aac54f7641e312b761188e44af2072e65f934d2b7e6b6b1c6ddf288fa3a76e0081ded8db60b959986c9fdaf2cb695a7116665939591fb9e18b
6
+ metadata.gz: 54b4b67e680719652cc4fa9494bfeb4bbf53f4545961225c2e4eb8a2f30d33490fe084fce3e9af531a354681d51dcde71ffea403eefdf89a032b92042c826148
7
+ data.tar.gz: 8e4d9362c99f7da3a14af78955968bacb31e286df4e57dd23fc3f678903f114d83e70dfe7d19c4c3370ef9b27ce59b0cf822ab25f8cb3c1d01868500bfcc3b63
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # RailsExportRoutes
1
+ # rails-export-routes
2
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/rails_export_routes`. 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
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
- Or install it yourself as:
17
+ ## Usage
20
18
 
21
- $ gem install rails_export_routes
19
+ To export Routes to CSV:
22
20
 
23
- ## Usage
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
- TODO: Write usage instructions here
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 `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/rails_export_routes.
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
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsExportRoutes
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  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.0
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-05 00:00:00.000000000 Z
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