rails_map 1.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.
- checksums.yaml +7 -0
- data/.idea/.gitignore +8 -0
- data/.idea/material_theme_project_new.xml +12 -0
- data/AUTHENTICATION.md +221 -0
- data/CHANGELOG.md +75 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/QUICKSTART.md +156 -0
- data/README.md +178 -0
- data/Rakefile +8 -0
- data/app/controllers/rails_map/docs_controller.rb +73 -0
- data/app/models/rails_map/user.rb +12 -0
- data/app/views/rails_map/docs/_styles.html.erb +489 -0
- data/app/views/rails_map/docs/controller.html.erb +137 -0
- data/app/views/rails_map/docs/index.html.erb +212 -0
- data/app/views/rails_map/docs/model.html.erb +214 -0
- data/app/views/rails_map/docs/routes.html.erb +139 -0
- data/config/initializers/rails_map.example.rb +44 -0
- data/config/routes.rb +9 -0
- data/docs/index.html +1354 -0
- data/lib/generators/rails_map/install_generator.rb +49 -0
- data/lib/generators/rails_map/templates/README +47 -0
- data/lib/generators/rails_map/templates/initializer.rb +38 -0
- data/lib/generators/rails_map/templates/migration.rb +14 -0
- data/lib/rails_map/auth.rb +15 -0
- data/lib/rails_map/configuration.rb +35 -0
- data/lib/rails_map/engine.rb +11 -0
- data/lib/rails_map/generators/html_generator.rb +120 -0
- data/lib/rails_map/parsers/model_parser.rb +257 -0
- data/lib/rails_map/parsers/route_parser.rb +356 -0
- data/lib/rails_map/railtie.rb +46 -0
- data/lib/rails_map/version.rb +5 -0
- data/lib/rails_map.rb +66 -0
- data/templates/controller.html.erb +74 -0
- data/templates/index.html.erb +64 -0
- data/templates/layout.html.erb +289 -0
- data/templates/model.html.erb +219 -0
- data/templates/routes.html.erb +86 -0
- metadata +144 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4df0308c2e2f34c47e8b9979ee52effe81267e74e2ac4dbaf626e830791f239f
|
|
4
|
+
data.tar.gz: '0306782d5ef8379eeb5699c53903df2bf9f1b08f24e5e55bd84770bf9302ef7c'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fb076b72fb3b392e0c772dd089ffe5c12f2c0846a88cddaa933d15d7bc629ad6df383378eb5a74cd01c740bc71ae8c4d24ba2fbd6a49688d0aae7b1efba8fb05
|
|
7
|
+
data.tar.gz: 92a0a50c1ef9739ce4220c351dc01af2e2d8e38af041b8041f56ae63eb8c45ef336b7f6aee1ffee47b10ac8c6472b4681a19f3b89a30e48a2cac81253b48c5e9
|
data/.idea/.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="MaterialThemeProjectNewConfig">
|
|
4
|
+
<option name="metadata">
|
|
5
|
+
<MTProjectMetadataState>
|
|
6
|
+
<option name="migrated" value="true" />
|
|
7
|
+
<option name="pristineConfig" value="false" />
|
|
8
|
+
<option name="userId" value="62b859e4:1995d57850e:-7ff9" />
|
|
9
|
+
</MTProjectMetadataState>
|
|
10
|
+
</option>
|
|
11
|
+
</component>
|
|
12
|
+
</project>
|
data/AUTHENTICATION.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Authentication Setup Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to protect your Rails documentation with authentication.
|
|
4
|
+
|
|
5
|
+
## Setup Steps
|
|
6
|
+
|
|
7
|
+
### 1. Mount the Engine
|
|
8
|
+
|
|
9
|
+
In your `config/routes.rb`:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
mount RailsMap::Engine, at: '/api-doc'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 2. Create Configuration File
|
|
16
|
+
|
|
17
|
+
Create `config/initializers/rails_map.rb` in your Rails application:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
RailsMap.configure do |config|
|
|
21
|
+
config.app_name = 'Your App Name'
|
|
22
|
+
config.theme_color = '#3B82F6'
|
|
23
|
+
|
|
24
|
+
# Add authentication
|
|
25
|
+
config.authenticate_with = proc {
|
|
26
|
+
# Your authentication logic here
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Authentication Examples
|
|
32
|
+
|
|
33
|
+
### Option 1: Built-in Authentication (Recommended)
|
|
34
|
+
|
|
35
|
+
If you don't use Devise, use the built-in authentication system.
|
|
36
|
+
|
|
37
|
+
**Setup:**
|
|
38
|
+
|
|
39
|
+
1. Install with authentication:
|
|
40
|
+
```bash
|
|
41
|
+
rails g rails_map:install
|
|
42
|
+
rails db:migrate
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. Create admin user(s):
|
|
46
|
+
```bash
|
|
47
|
+
rails c
|
|
48
|
+
RailsMap::User.create!(username: 'admin', password: 'your_secure_password')
|
|
49
|
+
RailsMap::User.create!(username: 'developer', password: 'another_password')
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. Enable in configuration:
|
|
53
|
+
```ruby
|
|
54
|
+
config.authenticate_with = proc {
|
|
55
|
+
RailsMap::Auth.authenticate(self)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
4. Restart server and visit `/api-doc` - you'll be prompted for username/password
|
|
60
|
+
|
|
61
|
+
**Managing Users:**
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
# Create user
|
|
65
|
+
RailsMap::User.create!(username: 'john', password: 'password123')
|
|
66
|
+
|
|
67
|
+
# Update password
|
|
68
|
+
user = RailsMap::User.find_by(username: 'john')
|
|
69
|
+
user.update!(password: 'new_password')
|
|
70
|
+
|
|
71
|
+
# Delete user
|
|
72
|
+
RailsMap::User.find_by(username: 'john').destroy
|
|
73
|
+
|
|
74
|
+
# List all users
|
|
75
|
+
RailsMap::User.all.pluck(:username)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Option 2: Devise Authentication
|
|
79
|
+
|
|
80
|
+
If you're using Devise:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
config.authenticate_with = proc {
|
|
84
|
+
authenticate_user!
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or restrict to admins only:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
config.authenticate_with = proc {
|
|
92
|
+
authenticate_user!
|
|
93
|
+
redirect_to root_path, alert: 'Not authorized' unless current_user.admin?
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Option 3: HTTP Basic Authentication
|
|
98
|
+
|
|
99
|
+
Simple username/password protection:
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
config.authenticate_with = proc {
|
|
103
|
+
authenticate_or_request_with_http_basic do |username, password|
|
|
104
|
+
username == 'admin' && password == 'secret'
|
|
105
|
+
end
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
With environment variables (recommended):
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
config.authenticate_with = proc {
|
|
113
|
+
authenticate_or_request_with_http_basic do |username, password|
|
|
114
|
+
username == ENV['DOC_USERNAME'] && password == ENV['DOC_PASSWORD']
|
|
115
|
+
end
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Option 4: Environment-Based Protection
|
|
120
|
+
|
|
121
|
+
Protect only in production:
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
config.authenticate_with = proc {
|
|
125
|
+
if Rails.env.production?
|
|
126
|
+
authenticate_or_request_with_http_basic do |username, password|
|
|
127
|
+
username == ENV['DOC_USERNAME'] && password == ENV['DOC_PASSWORD']
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Option 5: Custom Authentication Logic
|
|
134
|
+
|
|
135
|
+
Use any custom logic:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
config.authenticate_with = proc {
|
|
139
|
+
# Check session
|
|
140
|
+
unless session[:authenticated]
|
|
141
|
+
redirect_to login_path
|
|
142
|
+
return
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Check user role
|
|
146
|
+
unless current_user&.has_role?(:developer)
|
|
147
|
+
render plain: 'Unauthorized', status: :unauthorized
|
|
148
|
+
end
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Option 6: IP Whitelist
|
|
153
|
+
|
|
154
|
+
Restrict by IP address:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
config.authenticate_with = proc {
|
|
158
|
+
allowed_ips = ['127.0.0.1', '::1', '10.0.0.0/8']
|
|
159
|
+
|
|
160
|
+
unless allowed_ips.any? { |ip| IPAddr.new(ip).include?(request.remote_ip) }
|
|
161
|
+
render plain: 'Forbidden', status: :forbidden
|
|
162
|
+
end
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Testing Authentication
|
|
167
|
+
|
|
168
|
+
After configuring authentication:
|
|
169
|
+
|
|
170
|
+
1. Restart your Rails server
|
|
171
|
+
2. Visit `http://localhost:3000/api-doc`
|
|
172
|
+
3. You should be prompted to authenticate
|
|
173
|
+
|
|
174
|
+
## No Authentication (Development Only)
|
|
175
|
+
|
|
176
|
+
To disable authentication during development, simply don't set `authenticate_with` or use:
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
config.authenticate_with = nil
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Or conditionally:
|
|
183
|
+
|
|
184
|
+
```ruby
|
|
185
|
+
unless Rails.env.development?
|
|
186
|
+
config.authenticate_with = proc {
|
|
187
|
+
# Your auth logic
|
|
188
|
+
}
|
|
189
|
+
end
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Troubleshooting
|
|
193
|
+
|
|
194
|
+
### Infinite Redirect Loop
|
|
195
|
+
|
|
196
|
+
Make sure your authentication logic doesn't redirect to itself:
|
|
197
|
+
|
|
198
|
+
```ruby
|
|
199
|
+
# BAD - will cause infinite loop if not careful
|
|
200
|
+
config.authenticate_with = proc {
|
|
201
|
+
redirect_to login_path unless logged_in?
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
# GOOD - check if already on login page
|
|
205
|
+
config.authenticate_with = proc {
|
|
206
|
+
redirect_to login_path unless logged_in? || request.path == login_path
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Helper Methods Not Available
|
|
211
|
+
|
|
212
|
+
The authentication block runs in the controller context, so you have access to:
|
|
213
|
+
- `request`
|
|
214
|
+
- `session`
|
|
215
|
+
- `cookies`
|
|
216
|
+
- `params`
|
|
217
|
+
- `redirect_to`
|
|
218
|
+
- `render`
|
|
219
|
+
- Any helper methods from your application
|
|
220
|
+
|
|
221
|
+
If a method isn't available, you may need to include it in the engine controller or use a different approach.
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- API parameter detection and display for all routes
|
|
13
|
+
- Automatic extraction of path parameters (e.g., `:id`, `:user_id`)
|
|
14
|
+
- Query parameter detection for GET and DELETE requests
|
|
15
|
+
- Request body parameter detection for POST, PUT, and PATCH requests
|
|
16
|
+
- Intelligent type inference (string, integer, boolean, datetime, email, etc.)
|
|
17
|
+
- Required/optional parameter indication
|
|
18
|
+
- Parameter location display (path, query, or body)
|
|
19
|
+
- Expandable parameter details in routes and controller views
|
|
20
|
+
- Controller action analysis to extract permitted parameters
|
|
21
|
+
- Support for strong parameters pattern (`params.require().permit()`)
|
|
22
|
+
- Parameter documentation in both live and static HTML documentation
|
|
23
|
+
|
|
24
|
+
## [1.1.0] - 2026-02-10
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Live documentation via Rails Engine mounting at `/api-doc`
|
|
29
|
+
- Built-in authentication system (no Devise required) with `RailsMap::User` model
|
|
30
|
+
- Generator for easy installation: `rails g rails_map:install [--skip-auth]`
|
|
31
|
+
- Authentication enabled by default for security
|
|
32
|
+
- Use `--skip-auth` flag to disable authentication
|
|
33
|
+
- Automatically creates configuration file
|
|
34
|
+
- Automatically mounts engine in routes
|
|
35
|
+
- Automatically creates user migration (unless `--skip-auth`)
|
|
36
|
+
- Automatically adds `/doc/api` to `.gitignore`
|
|
37
|
+
- Authentication support with `authenticate_with` configuration option
|
|
38
|
+
- `RailsMap::Auth` helper module for authentication
|
|
39
|
+
- Example configuration file with authentication examples
|
|
40
|
+
- Comprehensive authentication guide (`AUTHENTICATION.md`)
|
|
41
|
+
- Quick start guide (`QUICKSTART.md`)
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- Improved card layout design with hover effects
|
|
46
|
+
- Better visual hierarchy for controller and model cards
|
|
47
|
+
- Enhanced responsive grid layout (350px min card width)
|
|
48
|
+
- Updated card styling with better spacing and shadows
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- Route constraint issue preventing access to namespaced controllers
|
|
53
|
+
- Support for nested controller names with slashes (e.g., `admin/users`)
|
|
54
|
+
|
|
55
|
+
## [1.0.0] - 2026-02-09
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
|
|
59
|
+
- Initial release
|
|
60
|
+
- Route parsing and documentation generation
|
|
61
|
+
- Model parsing with columns, associations, validations, and scopes
|
|
62
|
+
- HTML documentation generation with responsive design
|
|
63
|
+
- Rake tasks: `doc:generate`, `doc:open`, `doc:clean`
|
|
64
|
+
- Customizable configuration options:
|
|
65
|
+
- `output_dir` - Output directory for generated documentation
|
|
66
|
+
- `app_name` - Application name displayed in documentation
|
|
67
|
+
- `theme_color` - Theme color for UI customization
|
|
68
|
+
- `include_timestamps` - Toggle timestamp columns in model docs
|
|
69
|
+
- `include_validations` - Toggle validations in model docs
|
|
70
|
+
- `include_scopes` - Toggle scopes in model docs
|
|
71
|
+
- Color-coded HTTP method badges (GET, POST, PUT, PATCH, DELETE)
|
|
72
|
+
- Association type badges (belongs_to, has_many, has_one, has_and_belongs_to_many)
|
|
73
|
+
- Statistics dashboard with controller, route, and model counts
|
|
74
|
+
- Interlinked documentation pages for easy navigation
|
|
75
|
+
- Dark theme UI with modern design
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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.
|
data/QUICKSTART.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
🌐 **[Homepage](https://rails-map.netlify.app)** | 📚 **[Full Documentation](https://github.com/ArshdeepGrover/rails-map#readme)**
|
|
4
|
+
|
|
5
|
+
Get up and running with RailsMap in under 5 minutes!
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add to your `Gemfile`:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'rails_map'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
### Default Installation (With Authentication - Recommended)
|
|
24
|
+
|
|
25
|
+
1. Run the generator:
|
|
26
|
+
```bash
|
|
27
|
+
rails g rails_map:install
|
|
28
|
+
rails db:migrate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This automatically:
|
|
32
|
+
- ✅ Creates `config/initializers/rails_map.rb` with auth enabled
|
|
33
|
+
- ✅ Mounts the engine in `config/routes.rb`
|
|
34
|
+
- ✅ Creates user migration
|
|
35
|
+
- ✅ Adds `/doc/api` to `.gitignore`
|
|
36
|
+
|
|
37
|
+
2. Create an admin user:
|
|
38
|
+
```bash
|
|
39
|
+
rails c
|
|
40
|
+
RailsMap::User.create!(username: 'admin', password: 'your_secure_password')
|
|
41
|
+
exit
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. Start your server:
|
|
45
|
+
```bash
|
|
46
|
+
rails s
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Visit `http://localhost:3000/api-doc` and login with your credentials
|
|
50
|
+
|
|
51
|
+
**That's it!** 🎉 Secure by default!
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### Skip Authentication (Development Only)
|
|
56
|
+
|
|
57
|
+
1. Run the generator with --skip-auth flag:
|
|
58
|
+
```bash
|
|
59
|
+
rails g rails_map:install --skip-auth
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
2. Start your server:
|
|
63
|
+
```bash
|
|
64
|
+
rails s
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. Visit: `http://localhost:3000/api-doc`
|
|
68
|
+
|
|
69
|
+
**No authentication required!** Use only in development.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Customization
|
|
74
|
+
|
|
75
|
+
### Change Theme Color
|
|
76
|
+
|
|
77
|
+
In `config/initializers/rails_map.rb`:
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
config.theme_color = '#FF6B6B' # Any valid CSS color
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Change App Name
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
config.app_name = 'My Awesome API'
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Hide Timestamps in Models
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
config.include_timestamps = false
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Managing Users (Built-in Auth)
|
|
96
|
+
|
|
97
|
+
### Create User
|
|
98
|
+
```ruby
|
|
99
|
+
RailsMap::User.create!(username: 'developer', password: 'password123')
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Change Password
|
|
103
|
+
```ruby
|
|
104
|
+
user = RailsMap::User.find_by(username: 'developer')
|
|
105
|
+
user.update!(password: 'new_password')
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Delete User
|
|
109
|
+
```ruby
|
|
110
|
+
RailsMap::User.find_by(username: 'developer').destroy
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### List All Users
|
|
114
|
+
```ruby
|
|
115
|
+
RailsMap::User.all.pluck(:username)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Static HTML Generation (Optional)
|
|
119
|
+
|
|
120
|
+
If you want to generate static HTML files instead of using the live engine:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
rails doc:generate # Generate HTML files
|
|
124
|
+
rails doc:open # Open in browser
|
|
125
|
+
rails doc:clean # Remove generated files
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Files are generated in `doc/api/` by default.
|
|
129
|
+
|
|
130
|
+
## Troubleshooting
|
|
131
|
+
|
|
132
|
+
### Can't access /api-doc
|
|
133
|
+
- Make sure you've mounted the engine in `config/routes.rb`
|
|
134
|
+
- Restart your Rails server
|
|
135
|
+
|
|
136
|
+
### Authentication not working
|
|
137
|
+
- Verify you've run migrations: `rails db:migrate`
|
|
138
|
+
- Check that you've created a user
|
|
139
|
+
- Ensure authentication is enabled in the initializer
|
|
140
|
+
|
|
141
|
+
### Controllers with slashes not showing
|
|
142
|
+
- Update the gem to the latest version
|
|
143
|
+
- The route constraint issue has been fixed
|
|
144
|
+
|
|
145
|
+
## Next Steps
|
|
146
|
+
|
|
147
|
+
- Read [AUTHENTICATION.md](AUTHENTICATION.md) for advanced authentication options
|
|
148
|
+
- Read [README.md](README.md) for complete documentation
|
|
149
|
+
- Customize your theme color and app name
|
|
150
|
+
- Add authentication for production deployments
|
|
151
|
+
|
|
152
|
+
## Need Help?
|
|
153
|
+
|
|
154
|
+
- Check the [README.md](README.md) for detailed documentation
|
|
155
|
+
- Review [AUTHENTICATION.md](AUTHENTICATION.md) for authentication setup
|
|
156
|
+
- Open an issue on [GitHub](https://github.com/ArshdeepGrover/rails-map/issues)
|
data/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Rails Map
|
|
2
|
+
|
|
3
|
+
🌐 **[Homepage](https://rails-map.netlify.app)** | 📦 **[RubyGems](https://rubygems.org/gems/rails_map)** | 🐙 **[GitHub](https://github.com/ArshdeepGrover/rails-map)**
|
|
4
|
+
|
|
5
|
+
Automatically generates interactive API documentation for Rails by mapping routes, controllers, and models. Zero configuration—just install and go.
|
|
6
|
+
|
|
7
|
+
- **Routes** - All routes grouped by controller with HTTP methods, paths, and route names
|
|
8
|
+
- **Controllers** - Separate page for each controller with detailed route information
|
|
9
|
+
- **Models** - Separate page for each model with columns, associations, validations, and scopes
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'rails_map'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Quick Setup (With Authentication - Default)
|
|
26
|
+
|
|
27
|
+
Run the installer:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
rails g rails_map:install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Set environment variables (optional):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
export RAILS_MAP_USERNAME=admin
|
|
37
|
+
export RAILS_MAP_PASSWORD=your_secure_password
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or add to `.env` file:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
RAILS_MAP_USERNAME=admin
|
|
44
|
+
RAILS_MAP_PASSWORD=your_secure_password
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This automatically:
|
|
48
|
+
|
|
49
|
+
- ✅ Creates `config/initializers/rails_map.rb` with authentication enabled
|
|
50
|
+
- ✅ Mounts the engine at `/api-doc`
|
|
51
|
+
- ✅ Adds `/doc/api` to `.gitignore`
|
|
52
|
+
- ✅ Uses default credentials (admin/password) if ENV variables not set
|
|
53
|
+
|
|
54
|
+
Start your server and visit `http://localhost:3000/api-doc` - you'll be prompted to login!
|
|
55
|
+
|
|
56
|
+
### Setup Without Authentication
|
|
57
|
+
|
|
58
|
+
If you don't want authentication (development only recommended):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
rails g rails_map:install --skip-auth
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This will:
|
|
65
|
+
|
|
66
|
+
- ✅ Create the configuration file (auth disabled)
|
|
67
|
+
- ✅ Mount the engine at `/api-doc`
|
|
68
|
+
- ✅ Add `/doc/api` to `.gitignore`
|
|
69
|
+
|
|
70
|
+
Start your server and visit `/api-doc` - no login required!
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
### Live Documentation (Recommended)
|
|
75
|
+
|
|
76
|
+
Mount the engine in your `config/routes.rb`:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
mount RailsMap::Engine, at: '/api-doc'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Then visit `http://localhost:3000/api-doc` in your browser to see live documentation.
|
|
83
|
+
|
|
84
|
+
### Static HTML Generation
|
|
85
|
+
|
|
86
|
+
Run the following rake task to generate static HTML documentation:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
rails doc:generate
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This will generate HTML documentation in `doc/api/` directory.
|
|
93
|
+
|
|
94
|
+
### Open Documentation in Browser
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
rails doc:open
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Clean Generated Documentation
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
rails doc:clean
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
Create an initializer `config/initializers/rails_map.rb`:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
RailsMap.configure do |config|
|
|
112
|
+
# Output directory for generated documentation
|
|
113
|
+
config.output_dir = Rails.root.join('doc', 'api').to_s
|
|
114
|
+
|
|
115
|
+
# Application name displayed in the documentation
|
|
116
|
+
config.app_name = 'My Application'
|
|
117
|
+
|
|
118
|
+
# Theme color (any valid CSS color)
|
|
119
|
+
config.theme_color = '#3B82F6'
|
|
120
|
+
|
|
121
|
+
# Include timestamp columns (created_at, updated_at) in model documentation
|
|
122
|
+
config.include_timestamps = true
|
|
123
|
+
|
|
124
|
+
# Include model validations in documentation
|
|
125
|
+
config.include_validations = true
|
|
126
|
+
|
|
127
|
+
# Include model scopes in documentation
|
|
128
|
+
config.include_scopes = true
|
|
129
|
+
|
|
130
|
+
# Authentication - Protect documentation with authentication
|
|
131
|
+
# Uses environment variables: RAILS_MAP_USERNAME and RAILS_MAP_PASSWORD
|
|
132
|
+
# Defaults to username: admin, password: password
|
|
133
|
+
|
|
134
|
+
config.authenticate_with = proc {
|
|
135
|
+
RailsMap::Auth.authenticate(self)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Option 2: Devise
|
|
139
|
+
# config.authenticate_with = proc {
|
|
140
|
+
# authenticate_user!
|
|
141
|
+
# }
|
|
142
|
+
|
|
143
|
+
# Option 3: Custom logic
|
|
144
|
+
# config.authenticate_with = proc {
|
|
145
|
+
# redirect_to root_path unless current_user&.admin?
|
|
146
|
+
# }
|
|
147
|
+
end
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Features
|
|
151
|
+
|
|
152
|
+
- 📱 **Responsive Design** - Works on desktop and mobile
|
|
153
|
+
- 🎨 **Customizable Theme** - Change the primary color to match your brand
|
|
154
|
+
- 🔗 **Interlinked Pages** - Easy navigation between related models and controllers
|
|
155
|
+
- 🏷️ **HTTP Method Badges** - Color-coded badges for different HTTP methods
|
|
156
|
+
- 📊 **Statistics Dashboard** - Quick overview of your application structure
|
|
157
|
+
- 🔍 **Association Type Badges** - Visual distinction for different association types
|
|
158
|
+
- 📝 **API Parameter Detection** - Automatically extracts and displays parameters for each route
|
|
159
|
+
- Path parameters (`:id`, `:user_id`, etc.)
|
|
160
|
+
- Query parameters for GET/DELETE requests
|
|
161
|
+
- Request body parameters for POST/PUT/PATCH requests
|
|
162
|
+
- Type inference (string, integer, boolean, datetime, etc.)
|
|
163
|
+
- Required/optional indication
|
|
164
|
+
- Parameter location (path, query, body)
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
|
169
|
+
|
|
170
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
171
|
+
|
|
172
|
+
## Contributing
|
|
173
|
+
|
|
174
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ArshdeepGrover/rails-map.
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|