shorui 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c941e85895f0a8379bb62aad976170ad43e5f2e95c05563c511b9fed356112
4
- data.tar.gz: a49192b11854a42310fcdd2b8c4e159d092a2692c5864b0400e0a2fabd513c48
3
+ metadata.gz: 9f9102ca73aae7b5452034ed9d668f92c1b554185f8324a42f4674657129af7a
4
+ data.tar.gz: 628a0ec7d8e7c08b9d33df04ba98caefab6b4ca021da6c3a2759aacfcfcfc631
5
5
  SHA512:
6
- metadata.gz: da0a23b1b5ad8ddaa4db768598cb5fb97c9b71853b4f39a6df36f74aeba9b846762482ca9aac5966ae34bd86c895cb995abd8dfe8e0364a219217390a1859053
7
- data.tar.gz: 1c0a0f66a997cf2dd18f3457ef4c4ee14d1b85523042130f47cd1bb18ca116a98ad14d83bbc29154b7a57d31496d58ce1c3d43cc300f14eb74f90ed5d1dc25c4
6
+ metadata.gz: 6ff9d04b9906b7a439c8f631192b3a03184c00590f213e774cc52085e66798aae835a8df88f44b549751339a70ab42d9173a6998895497ae258150cc9e018d98
7
+ data.tar.gz: 47267c746dd62adddf119503d94d09c17deb2afe0ee3af1491469da8d39f18fca661040ae63dc2d030ad37cce224fdbbe8e380e6407e37162b69669a1343c11c
data/README.md CHANGED
@@ -1,43 +1,89 @@
1
1
  # Shorui
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/shorui.svg)](https://badge.fury.io/rb/shorui)
4
4
 
5
- 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/shorui`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Shorui is a Ruby gem that automatically generates API documentation by analyzing your Rails routes. It creates a clean, organized README.md file with detailed endpoint information.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ Add this line to your application's Gemfile:
10
10
 
11
- Install the gem and add to the application's Gemfile by executing:
11
+ ```ruby
12
+ gem 'shorui'
13
+ ```
12
14
 
15
+ And then execute:
13
16
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ $ bundle install
15
18
  ```
16
19
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
18
-
20
+ Or install it yourself as:
19
21
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
22
+ $ gem install shorui
21
23
  ```
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Shorui provides two Rake tasks:
28
+
29
+ 1. Generate full documentation including Rails routes:
30
+ ```bash
31
+ rails shorui:generate
32
+ ```
33
+
34
+ 2. Generate documentation excluding Rails routes:
35
+ ```bash
36
+ rails shorui:generate:no_rails_routes
37
+ ```
38
+
39
+ The gem will automatically:
40
+ - Analyze your Rails routes
41
+ - Extract controller and action information
42
+ - Identify required and optional parameters
43
+ - Generate a formatted README.md in your project root
44
+ - Include HTTP verbs, paths, and parameter details
45
+
46
+ ## Output Format
47
+
48
+ The generated README.md will follow this structure:
49
+
50
+ ```markdown
51
+ # Your Project Name API Documentation
52
+
53
+ #### [HTTP_VERB] /path/to/endpoint
54
+ - **Controller#Action:** `controller_name#action_name`
55
+ - **Required Params:** `param1, param2` (if any)
56
+ - **Optional Params:** `param1, param2` (if any)
57
+ ```
58
+
59
+ ## Features
60
+
61
+ - Automatic route analysis
62
+ - Clean and consistent documentation format
63
+ - Support for all HTTP verbs
64
+ - Parameter identification (required and optional)
65
+ - Rails route filtering option
66
+ - Proper handling of namespaced routes
67
+ - Automatic project name formatting
26
68
 
27
69
  ## Development
28
70
 
29
71
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
72
 
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
74
 
33
75
  ## Contributing
34
76
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shorui. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/shorui/blob/master/CODE_OF_CONDUCT.md).
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thiagochirana/shorui. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
36
78
 
37
79
  ## License
38
80
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
40
82
 
41
83
  ## Code of Conduct
42
84
 
43
- Everyone interacting in the Shorui project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shorui/blob/master/CODE_OF_CONDUCT.md).
85
+ Everyone interacting in the Shorui project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
86
+
87
+ ## Origins
88
+
89
+ "Shorui" (書類) means "document" in Japanese, reflecting the gem's purpose of automatic documentation generation.
@@ -1,29 +1,59 @@
1
1
  module Shorui
2
2
  class Generator
3
- def self.fetch_routes
3
+ def self.fetch_routes(ignore_rails_paths = false)
4
4
  Rails.application.routes.routes.map do |route|
5
- {
6
- path: route.path.spec.to_s,
7
- verb: route.verb,
8
- controller_action: route.defaults.slice(:controller, :action),
9
- }
10
- end.reject { |r| r[:path].include?('(.:format)') }
11
- end
5
+ path = route.path.spec.to_s.gsub("(.:format)", "")
6
+
7
+ if ignore_rails_paths && path.start_with?("/rails")
8
+ next
9
+ end
10
+
11
+ controller = route.defaults.dig(:controller)
12
+ action = route.defaults.dig(:action)
13
+
14
+ if controller && action
15
+ {
16
+ path: path,
17
+ verb: route.verb,
18
+ controller_action: { controller: controller, action: action },
19
+ required_params: route.path.required_names,
20
+ optional_params: route.defaults.keys - [:controller, :action]
21
+ }
22
+ end
23
+ end.compact
24
+ end
12
25
 
13
- def self.generate_readme
14
- routes = fetch_routes
15
- content = "# API Documentation\n\n"
26
+ def self.generate_readme(ignore_rails_paths = false)
27
+ routes = fetch_routes(ignore_rails_paths)
28
+ dir_name = File.basename(Dir.pwd)
29
+ formatted_name = dir_name.gsub(/[-_\/|\\.]/, ' ').split.map(&:capitalize).join(' ')
30
+ content = "# #{formatted_name} API Documentation\n\n"
16
31
 
17
32
  routes.each do |route|
18
- controller = route[:controller_action][:controller]
19
- action = route[:controller_action][:action]
20
- content << "## #{controller.camelize}##{action}\n"
21
- content << "- **Path:** `#{route[:path]}`\n"
22
- content << "- **HTTP Verb:** `#{route[:verb]}`\n\n"
23
- end
33
+ if route.nil?
34
+ next
35
+ end
36
+
37
+ if ignore_rails_paths
38
+ next if route[:verb].start_with?("/rails")
39
+ end
24
40
 
41
+ controller = route.dig(:controller_action, :controller)
42
+ action = route.dig(:controller_action, :action)
43
+
44
+ if controller && action
45
+ required_params = route[:required_params].any? ? route[:required_params].join(', ') : nil
46
+ optional_params = route[:optional_params].any? ? route[:optional_params].join(', ') : nil
47
+
48
+ content << "#### [#{route[:verb]}] #{route[:path]}\n"
49
+ content << "- **Controller#Action:** `#{controller}##{action}`\n"
50
+ content << "- **Required Params:** `#{required_params}`\n" if required_params
51
+ content << "- **Optional Params:** `#{optional_params}`\n\n" if optional_params
52
+ end
53
+ end
54
+
25
55
  File.write('README.md', content)
26
56
  puts "README.md successfully generated in #{Dir.pwd}!"
27
- end
57
+ end
28
58
  end
29
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shorui
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/shorui.rb CHANGED
@@ -1,9 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "shorui/version"
4
2
  require_relative "shorui/generator"
3
+ require 'rails'
5
4
 
6
5
  module Shorui
7
6
  class Error < StandardError; end
8
- # Your code goes here...
9
- end
7
+
8
+ class Railtie < Rails::Railtie
9
+ rake_tasks do
10
+ load File.expand_path('../tasks/shorui.rake', __FILE__)
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,11 @@
1
1
  namespace :shorui do
2
2
  desc "Generate README.md from routes"
3
- task generate: :environment do
4
- Shorui::Generator.generate_readme
3
+ task :generate => :environment do
4
+ Shorui::Generator.generate_readme(false)
5
5
  end
6
- end
6
+
7
+ desc "Generate README.md excluding Rails routes"
8
+ task :'generate:no_rails_routes' => :environment do
9
+ Shorui::Generator.generate_readme(true)
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shorui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DevCurumin
@@ -9,7 +9,35 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2025-01-20 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
13
41
  description: A gem that helps you generate README.md from routes.rb
14
42
  email:
15
43
  - thiago.chirana@gmail.com