rails_export_routes 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b3b758249798b4db8f7d467d746f2270d09337adf7af6ae9dfb8812bad1ec477
4
+ data.tar.gz: f26b25d605c5be2a2a81637707bfbe9aa001d1ed1f6bca85ee592f247d6d4ee6
5
+ SHA512:
6
+ metadata.gz: 48c7fbf70092b376cfbc7fd9bf44fe1e1c9d00a37ca7539b84f16085213df1988a52ff16821d9bf26c191c760771e770fc8815f6b685ef7e8f8bb1ea8cca96d9
7
+ data.tar.gz: 0b3c91f1d12409aac54f7641e312b761188e44af2072e65f934d2b7e6b6b1c6ddf288fa3a76e0081ded8db60b959986c9fdaf2cb695a7116665939591fb9e18b
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Lenon Marcel
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.
@@ -0,0 +1,40 @@
1
+ # RailsExportRoutes
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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails_export_routes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_export_routes
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 tags, 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]/rails_export_routes.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rails_export_routes'
5
+
6
+ RailsExportRoutes::CLI.start(ARGV)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_export_routes/version'
4
+ require 'rails_export_routes/route_wrapper'
5
+ require 'rails_export_routes/formatters/csv'
6
+ require 'rails_export_routes/formatters/json'
7
+ require 'rails_export_routes/cli'
8
+
9
+ module RailsExportRoutes
10
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module RailsExportRoutes
6
+ class CLI < Thor
7
+ def self.exit_on_failure?
8
+ true # Thor must exit with status 1 on errors
9
+ end
10
+
11
+ desc('export FILE', 'export Rails routes to FILE')
12
+ method_option(:format, type: :string,
13
+ default: 'csv',
14
+ enum: %w[csv json])
15
+ def export(file)
16
+ load_rails_app(Dir.pwd)
17
+
18
+ formatter = case options.fetch(:format)
19
+ when 'csv' then Formatters::CSV
20
+ when 'json' then Formatters::JSON
21
+ end
22
+
23
+ formatter.new(wrapped_rails_routes).export_to_file(file)
24
+ end
25
+
26
+ no_commands do
27
+ def load_rails_app(app_path)
28
+ require "#{app_path}/config/environment.rb"
29
+ rescue ::LoadError
30
+ raise Error, "Rails app not found in #{app_path}"
31
+ end
32
+
33
+ def wrapped_rails_routes
34
+ Rails.application.routes.routes.reject(&:internal).map do |route|
35
+ RouteWrapper.new(route)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'json'
5
+
6
+ module RailsExportRoutes
7
+ module Formatters
8
+ class CSV
9
+ def initialize(routes)
10
+ @routes = routes
11
+ end
12
+
13
+ def export_to_file(file) # rubocop:disable Metrics/MethodLength
14
+ ::CSV.open(file, 'wb') do |csv|
15
+ csv << %w[verb path controller action name constraints]
16
+
17
+ @routes.each do |route|
18
+ csv << [
19
+ route.verb,
20
+ route.path_spec,
21
+ route.controller,
22
+ route.action,
23
+ route.name,
24
+ route.constraints.to_json
25
+ ]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module RailsExportRoutes
6
+ module Formatters
7
+ class JSON
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.generate(data))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+
5
+ module RailsExportRoutes
6
+ class RouteWrapper < SimpleDelegator
7
+ def path_spec
8
+ path.spec.to_s
9
+ end
10
+
11
+ def controller
12
+ requirements[:controller]
13
+ end
14
+
15
+ def action
16
+ requirements[:action]
17
+ end
18
+
19
+ def constraints
20
+ requirements.except(:controller, :action)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsExportRoutes
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_export_routes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lenon Marcel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.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: 6.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Tool to export Rails routes to CSV
42
+ email:
43
+ - lenon.marcel@gmail.com
44
+ executables:
45
+ - rails-export-routes
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.txt
50
+ - README.md
51
+ - exe/rails-export-routes
52
+ - lib/rails_export_routes.rb
53
+ - lib/rails_export_routes/cli.rb
54
+ - lib/rails_export_routes/formatters/csv.rb
55
+ - lib/rails_export_routes/formatters/json.rb
56
+ - lib/rails_export_routes/route_wrapper.rb
57
+ - lib/rails_export_routes/version.rb
58
+ homepage: https://github.com/lenon/rails_export_routes
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ homepage_uri: https://github.com/lenon/rails_export_routes
64
+ source_code_uri: https://github.com/lenon/rails_export_routes
65
+ changelog_uri: https://github.com/lenon/rails_export_routes/blob/main/CHANGELOG.md
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.3.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.4
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Tool to export Rails routes to CSV
85
+ test_files: []