railsforge 1.0.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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +528 -0
  4. data/bin/railsforge +8 -0
  5. data/lib/railsforge/analyzers/base_analyzer.rb +41 -0
  6. data/lib/railsforge/analyzers/controller_analyzer.rb +83 -0
  7. data/lib/railsforge/analyzers/database_analyzer.rb +55 -0
  8. data/lib/railsforge/analyzers/metrics_analyzer.rb +55 -0
  9. data/lib/railsforge/analyzers/model_analyzer.rb +74 -0
  10. data/lib/railsforge/analyzers/performance_analyzer.rb +161 -0
  11. data/lib/railsforge/analyzers/refactor_analyzer.rb +118 -0
  12. data/lib/railsforge/analyzers/security_analyzer.rb +169 -0
  13. data/lib/railsforge/analyzers/spec_analyzer.rb +58 -0
  14. data/lib/railsforge/api_generator.rb +397 -0
  15. data/lib/railsforge/audit.rb +289 -0
  16. data/lib/railsforge/cli.rb +671 -0
  17. data/lib/railsforge/config.rb +181 -0
  18. data/lib/railsforge/database_analyzer.rb +300 -0
  19. data/lib/railsforge/doctor.rb +250 -0
  20. data/lib/railsforge/feature_generator.rb +560 -0
  21. data/lib/railsforge/generator.rb +313 -0
  22. data/lib/railsforge/generators/base_generator.rb +70 -0
  23. data/lib/railsforge/generators/demo_generator.rb +307 -0
  24. data/lib/railsforge/generators/devops_generator.rb +287 -0
  25. data/lib/railsforge/generators/monitoring_generator.rb +134 -0
  26. data/lib/railsforge/generators/service_generator.rb +122 -0
  27. data/lib/railsforge/generators/stimulus_controller_generator.rb +129 -0
  28. data/lib/railsforge/generators/test_generator.rb +289 -0
  29. data/lib/railsforge/generators/view_component_generator.rb +169 -0
  30. data/lib/railsforge/graph.rb +270 -0
  31. data/lib/railsforge/loader.rb +56 -0
  32. data/lib/railsforge/mailer_generator.rb +191 -0
  33. data/lib/railsforge/plugins/plugin_loader.rb +60 -0
  34. data/lib/railsforge/plugins.rb +30 -0
  35. data/lib/railsforge/profiles/admin_app.yml +49 -0
  36. data/lib/railsforge/profiles/api_only.yml +47 -0
  37. data/lib/railsforge/profiles/blog.yml +47 -0
  38. data/lib/railsforge/profiles/standard.yml +44 -0
  39. data/lib/railsforge/profiles.rb +99 -0
  40. data/lib/railsforge/refactor_analyzer.rb +401 -0
  41. data/lib/railsforge/refactor_controller.rb +277 -0
  42. data/lib/railsforge/refactors/refactor_controller.rb +117 -0
  43. data/lib/railsforge/template_loader.rb +105 -0
  44. data/lib/railsforge/templates/v1/form/spec_template.rb +18 -0
  45. data/lib/railsforge/templates/v1/form/template.rb +28 -0
  46. data/lib/railsforge/templates/v1/job/spec_template.rb +17 -0
  47. data/lib/railsforge/templates/v1/job/template.rb +13 -0
  48. data/lib/railsforge/templates/v1/policy/spec_template.rb +41 -0
  49. data/lib/railsforge/templates/v1/policy/template.rb +57 -0
  50. data/lib/railsforge/templates/v1/presenter/spec_template.rb +12 -0
  51. data/lib/railsforge/templates/v1/presenter/template.rb +13 -0
  52. data/lib/railsforge/templates/v1/query/spec_template.rb +12 -0
  53. data/lib/railsforge/templates/v1/query/template.rb +16 -0
  54. data/lib/railsforge/templates/v1/serializer/spec_template.rb +13 -0
  55. data/lib/railsforge/templates/v1/serializer/template.rb +11 -0
  56. data/lib/railsforge/templates/v1/service/spec_template.rb +12 -0
  57. data/lib/railsforge/templates/v1/service/template.rb +25 -0
  58. data/lib/railsforge/templates/v1/stimulus_controller/template.rb +35 -0
  59. data/lib/railsforge/templates/v1/view_component/template.rb +24 -0
  60. data/lib/railsforge/templates/v2/job/template.rb +49 -0
  61. data/lib/railsforge/templates/v2/query/template.rb +66 -0
  62. data/lib/railsforge/templates/v2/service/spec_template.rb +33 -0
  63. data/lib/railsforge/templates/v2/service/template.rb +71 -0
  64. data/lib/railsforge/templates/v3/job/template.rb +72 -0
  65. data/lib/railsforge/templates/v3/query/spec_template.rb +54 -0
  66. data/lib/railsforge/templates/v3/query/template.rb +115 -0
  67. data/lib/railsforge/templates/v3/service/spec_template.rb +51 -0
  68. data/lib/railsforge/templates/v3/service/template.rb +84 -0
  69. data/lib/railsforge/version.rb +5 -0
  70. data/lib/railsforge/wizard.rb +265 -0
  71. data/lib/railsforge/wizard_tui.rb +286 -0
  72. data/lib/railsforge.rb +13 -0
  73. metadata +216 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a30814a978c1f6eae732253edaf8ebde7fb49b5761ef1927f180a5480f3f7921
4
+ data.tar.gz: 4dfd319836fd20dcc79ac23d0c5eeb644802b9f6d480956dbae89cfeb5ef39ed
5
+ SHA512:
6
+ metadata.gz: eb2d18edddb6280e6b1eb954efb13a7acedc9e1fc429a7257e59282cbb2225293a0c028b5c34a3b1e1c18f3e7875c1868e4472a8b39b6b90ba6d7e24cd7803b9
7
+ data.tar.gz: a8fee69a296ec94b93aecbd6f89223c5fcda26ff37dd6fb96081394dbc7856dd92f5c4a445ac2cd1a7f549c0159ca712f0e0680ad1987dfd166f10bf7a908d1f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Quinto
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,528 @@
1
+ # RailsForge
2
+
3
+ <p align="center">
4
+ <a href="https://github.com/railsforge/railsforge/actions">
5
+ <img src="https://img.shields.io/github/actions/workflow/status/railsforge/railsforge/main.yml" alt="CI Status">
6
+ </a>
7
+ <a href="https://rubygems.org/gems/railsforge">
8
+ <img src="https://img.shields.io/gem/v/railsforge" alt="Gem Version">
9
+ </a>
10
+ <a href="https://rubygems.org/gems/railsforge">
11
+ <img src="https://img.shields.io/gem/dt/railsforge" alt="Gem Downloads">
12
+ </a>
13
+ <a href="https://github.com/railsforge/railsforge/blob/main/LICENSE">
14
+ <img src="https://img.shields.io/github/license/railsforge/railsforge" alt="License">
15
+ </a>
16
+ </p>
17
+
18
+ RailsForge is a comprehensive command-line tool for automatically generating essential Rails application components, including monitoring configurations, DevOps setups, and security/performance analyzers.
19
+
20
+ ## Project Overview
21
+
22
+ RailsForge streamlines Rails development by providing automated generators and analyzers for common tasks:
23
+
24
+ - **Monitoring Configuration** - Sentry error tracking and Lograge structured logging
25
+ - **DevOps Setup** - Docker containerization and CI/CD pipeline configuration
26
+ - **Security Analysis** - Automated vulnerability detection
27
+ - **Performance Analysis** - Performance optimization recommendations
28
+ - **Code Generation** - Services, queries, jobs, and more with template versioning
29
+
30
+ ### Key Features
31
+
32
+ - 🔧 **Automated Generators** - Generate services, queries, jobs, components with a single command
33
+ - 📊 **Code Analyzers** - Security, performance, and architectural analysis
34
+ - 🐳 **DevOps Ready** - Docker and CI/CD configuration out of the box
35
+ - 📈 **Monitoring** - Sentry and Lograge integration
36
+ - 🎨 **Template System** - v1, v2, and v3 template versions with advanced patterns
37
+ - 🧩 **Plugin System** - Extensible architecture for custom functionality
38
+ - ⚙️ **Configuration** - Customizable via `.railsforgerc` YAML file
39
+
40
+ ## Installation
41
+
42
+ ### Requirements
43
+
44
+ - **Ruby** version 2.7 or higher
45
+ - **Rails** version 5.0 or higher (for Rails-specific features)
46
+ - **Bundler** for gem management
47
+
48
+ ### Setup Steps
49
+
50
+ #### Option 1: Install from RubyGems (Recommended)
51
+
52
+ ```bash
53
+ # Install the gem
54
+ gem install railsforge
55
+
56
+ # Verify installation
57
+ railsforge --version
58
+ ```
59
+
60
+ #### Option 2: Install from Source
61
+
62
+ ```bash
63
+ # Clone the repository
64
+ git clone https://github.com/mfifth/railsforge.git
65
+ cd railsforge
66
+
67
+ # Install dependencies
68
+ bundle install
69
+
70
+ # Make the binary executable
71
+ chmod +x bin/railsforge
72
+
73
+ # Run locally
74
+ ./bin/railsforge --version
75
+ ```
76
+
77
+ #### Option 3: Add to Gemfile
78
+
79
+ ```ruby
80
+ # Add to your Rails project's Gemfile
81
+ group :development do
82
+ gem 'railsforge', require: false
83
+ end
84
+ ```
85
+
86
+ Then run:
87
+
88
+ ```bash
89
+ bundle install
90
+ ```
91
+
92
+ ## Usage Documentation
93
+
94
+ ### Getting Help
95
+
96
+ ```bash
97
+ railsforge --help
98
+ railsforge --version
99
+ ```
100
+
101
+ ### Generate Commands
102
+
103
+ #### Monitoring Configuration
104
+
105
+ Add Sentry error tracking and Lograge structured logging to your Rails application:
106
+
107
+ ```bash
108
+ railsforge generate monitoring
109
+ railsforge generate monitoring --sentry_dsn=your_dsn_here
110
+ railsforge generate monitoring --environment=production
111
+ ```
112
+
113
+ This creates:
114
+ - `config/initializers/sentry.rb` - Sentry configuration
115
+ - `config/initializers/lograge.rb` - Lograge setup
116
+ - Updates environment configurations
117
+
118
+ #### DevOps Configuration
119
+
120
+ Generate Docker and CI/CD pipeline configurations:
121
+
122
+ ```bash
123
+ railsforge generate devops
124
+ railsforge generate devops --docker
125
+ railsforge generate devops --ci=github
126
+ railsforge generate devops --ci=gitlab
127
+ ```
128
+
129
+ This creates:
130
+ - `Dockerfile` - Container definition
131
+ - `docker-compose.yml` - Multi-service setup
132
+ - `.github/workflows/ci.yml` - GitHub Actions CI/CD
133
+ - `.gitlab-ci.yml` - GitLab CI configuration
134
+ - `config/kubernetes/` - Kubernetes manifests
135
+ - `bin/deploy` - Deployment script
136
+
137
+ #### Demo Project
138
+
139
+ Create a sample Rails project for learning or prototyping:
140
+
141
+ ```bash
142
+ railsforge generate demo my_demo
143
+ railsforge generate demo my_demo --type=blog
144
+ railsforge generate demo my_api --type=api
145
+ ```
146
+
147
+ #### Test Files
148
+
149
+ Generate comprehensive test files:
150
+
151
+ ```bash
152
+ railsforge generate test User
153
+ railsforge generate test PostsController --type=controller
154
+ railsforge generate test UserService --type=service
155
+ railsforge generate test SendEmailJob --type=job
156
+ ```
157
+
158
+ #### Standard Generators
159
+
160
+ Generate Rails components with template versioning:
161
+
162
+ ```bash
163
+ # Service objects
164
+ railsforge generate service user_creator
165
+ railsforge generate service user_creator --template=v2
166
+ railsforge generate service user_creator --template=v3
167
+
168
+ # Query objects
169
+ railsforge generate query active_users
170
+ railsforge generate query posts --template=v2
171
+
172
+ # Jobs
173
+ railsforge generate job send_email
174
+ railsforge generate job process_data --template=v3
175
+
176
+ # Form objects
177
+ railsforge generate form contact_form
178
+
179
+ # Presenters
180
+ railsforge generate presenter user_presenter
181
+
182
+ # Policies
183
+ railsforge generate policy post_policy
184
+
185
+ # Serializers
186
+ railsforge generate serializer post_serializer
187
+
188
+ # View Components
189
+ railsforge generate component button
190
+ railsforge generate component modal --template=v2
191
+
192
+ # Stimulus Controllers
193
+ railsforge generate stimulus dropdown
194
+
195
+ # Mailers
196
+ railsforge generate mailer user_mailer
197
+
198
+ # Features
199
+ railsforge generate feature user_signup
200
+
201
+ # API Resources
202
+ railsforge generate api posts
203
+ ```
204
+
205
+ ### Analyze Commands
206
+
207
+ #### Security Analysis
208
+
209
+ Run security vulnerability checks on your codebase:
210
+
211
+ ```bash
212
+ railsforge analyze security
213
+ railsforge analyze security --verbose
214
+ ```
215
+
216
+ Checks for:
217
+ - SQL injection vulnerabilities
218
+ - Cross-site scripting (XSS) risks
219
+ - Authentication/authorization issues
220
+ - Insecure configuration patterns
221
+ - Sensitive data exposure
222
+
223
+ #### Performance Analysis
224
+
225
+ Identify performance optimization opportunities:
226
+
227
+ ```bash
228
+ railsforge analyze performance
229
+ railsforge analyze performance --verbose
230
+ ```
231
+
232
+ Checks for:
233
+ - N+1 query patterns
234
+ - Missing database indexes
235
+ - Inefficient queries
236
+ - Memory leak patterns
237
+ - Unoptimized asset loading
238
+
239
+ #### Other Analyzers
240
+
241
+ ```bash
242
+ # Analyze controllers
243
+ railsforge analyze controllers
244
+ railsforge analyze c
245
+
246
+ # Analyze models
247
+ railsforge analyze models
248
+ railsforge analyze m
249
+
250
+ # Analyze specs
251
+ railsforge analyze specs
252
+ railsforge analyze spec
253
+
254
+ # Analyze database
255
+ railsforge analyze db
256
+ railsforge analyze database
257
+
258
+ # Analyze metrics
259
+ railsforge analyze metrics
260
+
261
+ # Run all analyzers
262
+ railsforge analyze all
263
+ railsforge analyze full
264
+ ```
265
+
266
+ ### Other Commands
267
+
268
+ #### Doctor - Health Check
269
+
270
+ Comprehensive project health report:
271
+
272
+ ```bash
273
+ railsforge doctor
274
+ ```
275
+
276
+ Combines all analyzers and calculates an architecture score (0-100).
277
+
278
+ #### Dependency Graph
279
+
280
+ Generate a Graphviz diagram of your Rails architecture:
281
+
282
+ ```bash
283
+ railsforge graph
284
+ ```
285
+
286
+ Outputs `.dot` and `.svg` files to `tmp/railsforge/`.
287
+
288
+ #### Wizard - Interactive Setup
289
+
290
+ Interactive project configuration:
291
+
292
+ ```bash
293
+ railsforge wizard
294
+ railsforge wizard --profile=blog
295
+ ```
296
+
297
+ #### Plugin Management
298
+
299
+ ```bash
300
+ # List available plugins
301
+ railsforge plugins list
302
+
303
+ # Load a specific plugin
304
+ railsforge plugins load my_plugin
305
+ ```
306
+
307
+ #### Configuration
308
+
309
+ ```bash
310
+ # View current configuration
311
+ railsforge config
312
+
313
+ # Set configuration values
314
+ railsforge config set default_template v2
315
+ railsforge config set analyzer_threshold 10
316
+ ```
317
+
318
+ #### Profiles
319
+
320
+ List available project profiles:
321
+
322
+ ```bash
323
+ railsforge profiles
324
+ ```
325
+
326
+ Available profiles: blog, admin_app, api_only, standard
327
+
328
+ ## Configuration Options
329
+
330
+ ### .railsforgerc
331
+
332
+ Create a `.railsforgerc` file in your project root to customize RailsForge behavior:
333
+
334
+ ```yaml
335
+ # .railsforgerc
336
+ default_template: v2
337
+ analyzer_threshold: 10
338
+
339
+ # Generator settings
340
+ generators:
341
+ with_specs: true
342
+ template_version: v2
343
+
344
+ # Analyzer settings
345
+ security:
346
+ strict_mode: true
347
+ performance:
348
+ check_n_plus_queries: true
349
+ ```
350
+
351
+ ### Available Flags
352
+
353
+ | Flag | Description | Default |
354
+ |------|-------------|---------|
355
+ | `--sentry_dsn` | Sentry DSN for error tracking | - |
356
+ | `--environment` | Rails environment | development |
357
+ | `--template` | Template version (v1, v2, v3) | v1 |
358
+ | `--dry-run` | Preview changes without executing | false |
359
+ | `--no-spec` | Generate without spec files | false |
360
+
361
+ ## Template System
362
+
363
+ RailsForge supports multiple template versions for each component:
364
+
365
+ ### v1 - Standard Templates
366
+
367
+ Basic templates suitable for simple applications:
368
+
369
+ ```ruby
370
+ class UserCreator
371
+ def initialize(params)
372
+ @params = params
373
+ end
374
+
375
+ def call
376
+ # Basic implementation
377
+ end
378
+ end
379
+ ```
380
+
381
+ ### v2 - Enhanced Templates
382
+
383
+ Enhanced templates with additional features:
384
+
385
+ ```ruby
386
+ class UserCreator < BaseService
387
+ option :name
388
+
389
+ def call
390
+ # Enhanced with Dry::Schema validation
391
+ end
392
+ end
393
+ ```
394
+
395
+ ### v3 - Advanced Templates
396
+
397
+ Advanced templates with best practices:
398
+
399
+ ```ruby
400
+ class UserCreator
401
+ include Dry::Monads[:result, :do]
402
+
403
+ def call
404
+ yield validate!
405
+ yield process!
406
+ Success(result_data)
407
+ end
408
+ end
409
+ ```
410
+
411
+ ## Examples
412
+
413
+ ### Complete Workflow Example
414
+
415
+ ```bash
416
+ # 1. Create a new Rails app (optional)
417
+ railsforge new my_app --profile=api
418
+
419
+ # 2. Add monitoring
420
+ cd my_app
421
+ railsforge generate monitoring --sentry_dsn=https://key@sentry.io/123
422
+
423
+ # 3. Add DevOps setup
424
+ railsforge generate devops --ci=github
425
+
426
+ # 4. Generate components
427
+ railsforge generate service user_creator --template=v3
428
+ railsforge generate job send_welcome_email --template=v3
429
+ railsforge generate query active_users --template=v3
430
+
431
+ # 5. Run analysis
432
+ railsforge analyze all
433
+ railsforge doctor
434
+
435
+ # 6. Check architecture
436
+ railsforge graph
437
+ ```
438
+
439
+ ### Output Examples
440
+
441
+ ```
442
+ $ railsforge generate monitoring
443
+ Generating Monitoring configurations...
444
+ Created config/initializers/sentry.rb
445
+ Created config/initializers/lograge.rb
446
+ Updated production.rb
447
+
448
+ $ railsforge analyze security
449
+ Security Analysis
450
+ ==================================================
451
+ ✓ No security issues found
452
+
453
+ $ railsforge analyze performance
454
+ Performance Analysis
455
+ ==================================================
456
+ ✓ No performance issues found
457
+ ```
458
+
459
+ ## Contributing
460
+
461
+ We welcome contributions! Please see our contributing guidelines:
462
+
463
+ ### Development Setup
464
+
465
+ ```bash
466
+ # Fork the repository
467
+ git clone https://github.com/your-username/railsforge.git
468
+ cd railsforge
469
+
470
+ # Install dependencies
471
+ bundle install
472
+
473
+ # Run tests
474
+ bundle exec rake test
475
+
476
+ # Run linter
477
+ bundle exec rubocop
478
+ ```
479
+
480
+ ### Submitting Changes
481
+
482
+ 1. Fork the repository
483
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
484
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
485
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
486
+ 5. Open a Pull Request
487
+
488
+ ### Code Style
489
+
490
+ - Follow Ruby community style guides
491
+ - Write tests for new features
492
+ - Update documentation for any changes
493
+ - Use meaningful commit messages
494
+
495
+ ## License
496
+
497
+ RailsForge is released under the MIT License.
498
+
499
+ Copyright (c) 2024 RailsForge Contributors
500
+
501
+ Permission is hereby granted, free of charge, to any person obtaining a copy
502
+ of this software and associated documentation files (the "Software"), to deal
503
+ in the Software without restriction, including without limitation the rights
504
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
505
+ copies of the Software, and to permit persons to whom the Software is
506
+ furnished to do so, subject to the following conditions:
507
+
508
+ The above copyright notice and this permission notice shall be included in all
509
+ copies or substantial portions of the Software.
510
+
511
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
512
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
513
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
514
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
515
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
516
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
517
+ SOFTWARE.
518
+
519
+ ## Support
520
+
521
+ - 📖 [Documentation](https://github.com/railsforge/railsforge/wiki)
522
+ - 🐛 [Issue Tracker](https://github.com/railsforge/railsforge/issues)
523
+ - 💬 [Discussions](https://github.com/railsforge/railsforge/discussions)
524
+ - ⭐ [Give us a star](https://github.com/railsforge/railsforge)
525
+
526
+ ---
527
+
528
+ <p align="center">Built with ❤️ for the Rails community</p>
data/bin/railsforge ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # CLI entrypoint for RailsForge gem
3
+ # This file is executable from the command line
4
+
5
+ require_relative "../lib/railsforge"
6
+
7
+ # Delegate to RailsForge::CLI
8
+ RailsForge::CLI.start(ARGV)
@@ -0,0 +1,41 @@
1
+ # Base analyzer class for RailsForge
2
+ # All analyzers inherit from this class
3
+
4
+ module RailsForge
5
+ module Analyzers
6
+ # Base class for all analyzers
7
+ class BaseAnalyzer
8
+ # Find Rails app path (class method)
9
+ # @return [String, nil] Rails app root path
10
+ def self.find_rails_app_path
11
+ path = Dir.pwd
12
+ max_depth = 10
13
+
14
+ max_depth.times do
15
+ return path if File.exist?(File.join(path, "config", "application.rb"))
16
+ parent = File.dirname(path)
17
+ break if parent == path
18
+ path = parent
19
+ end
20
+
21
+ nil
22
+ end
23
+
24
+ # Find Rails app path (instance method)
25
+ # @return [String, nil] Rails app root path
26
+ def find_rails_app_path
27
+ self.class.find_rails_app_path
28
+ end
29
+
30
+ # Analyze - must be implemented by subclasses
31
+ def self.analyze(base_path = nil)
32
+ raise NotImplementedError, "Subclasses must implement #analyze"
33
+ end
34
+
35
+ # Instance analyze method
36
+ def analyze
37
+ self.class.analyze
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,83 @@
1
+ # Controller analyzer for RailsForge
2
+ # Scans controllers for code quality issues
3
+
4
+ require_relative 'base_analyzer'
5
+
6
+ module RailsForge
7
+ module Analyzers
8
+ # ControllerAnalyzer scans controllers for issues
9
+ class ControllerAnalyzer < BaseAnalyzer
10
+ # Configuration thresholds
11
+ MAX_LINES = 150
12
+ MAX_METHODS = 10
13
+
14
+ # Analyze controllers
15
+ # @param base_path [String] Rails app root
16
+ # @return [Array<Hash>] Analysis results
17
+ def self.analyze(base_path = nil)
18
+ base_path ||= find_rails_app_path
19
+ return [] unless base_path
20
+
21
+ controllers_dir = File.join(base_path, "app", "controllers")
22
+ return [] unless Dir.exist?(controllers_dir)
23
+
24
+ results = []
25
+ Dir.glob(File.join(controllers_dir, "**", "*_controller.rb")).each do |file|
26
+ next if file.end_with?("_application_controller.rb")
27
+
28
+ content = File.read(file)
29
+ lines = content.lines.count
30
+ methods = content.scan(/def \w+/).count
31
+
32
+ issues = []
33
+ issues << "Exceeds #{MAX_LINES} lines" if lines > MAX_LINES
34
+ issues << "Has #{methods} methods (max: #{MAX_METHODS})" if methods > MAX_METHODS
35
+
36
+ if issues.any?
37
+ results << {
38
+ file: File.basename(file),
39
+ path: file,
40
+ lines: lines,
41
+ methods: methods,
42
+ issues: issues
43
+ }
44
+ end
45
+ end
46
+
47
+ results
48
+ end
49
+
50
+ # Print results
51
+ def self.print_results(results)
52
+ puts "\nController Analysis"
53
+ puts "-" * 40
54
+
55
+ if results.empty?
56
+ puts "✓ No issues found"
57
+ return
58
+ end
59
+
60
+ results.each do |result|
61
+ puts "⚠ #{result[:file]}"
62
+ puts " Lines: #{result[:lines]}, Methods: #{result[:methods]}"
63
+ result[:issues].each { |issue| puts " - #{issue}" }
64
+ end
65
+ end
66
+
67
+ # Find Rails app path
68
+ def self.find_rails_app_path
69
+ path = Dir.pwd
70
+ max_depth = 10
71
+
72
+ max_depth.times do
73
+ return path if File.exist?(File.join(path, "config", "application.rb"))
74
+ parent = File.dirname(path)
75
+ break if parent == path
76
+ path = parent
77
+ end
78
+
79
+ nil
80
+ end
81
+ end
82
+ end
83
+ end