rails_lens 0.0.0 → 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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE.txt +2 -2
  4. data/README.md +393 -9
  5. data/exe/rails_lens +25 -0
  6. data/lib/rails_lens/analyzers/association_analyzer.rb +111 -0
  7. data/lib/rails_lens/analyzers/base.rb +35 -0
  8. data/lib/rails_lens/analyzers/best_practices_analyzer.rb +114 -0
  9. data/lib/rails_lens/analyzers/column_analyzer.rb +97 -0
  10. data/lib/rails_lens/analyzers/composite_keys.rb +62 -0
  11. data/lib/rails_lens/analyzers/database_constraints.rb +35 -0
  12. data/lib/rails_lens/analyzers/delegated_types.rb +124 -0
  13. data/lib/rails_lens/analyzers/enums.rb +34 -0
  14. data/lib/rails_lens/analyzers/error_handling.rb +66 -0
  15. data/lib/rails_lens/analyzers/foreign_key_analyzer.rb +47 -0
  16. data/lib/rails_lens/analyzers/generated_columns.rb +56 -0
  17. data/lib/rails_lens/analyzers/index_analyzer.rb +128 -0
  18. data/lib/rails_lens/analyzers/inheritance.rb +212 -0
  19. data/lib/rails_lens/analyzers/notes.rb +325 -0
  20. data/lib/rails_lens/analyzers/performance_analyzer.rb +110 -0
  21. data/lib/rails_lens/annotation_pipeline.rb +87 -0
  22. data/lib/rails_lens/cli.rb +170 -0
  23. data/lib/rails_lens/cli_error_handler.rb +86 -0
  24. data/lib/rails_lens/commands.rb +164 -0
  25. data/lib/rails_lens/connection.rb +133 -0
  26. data/lib/rails_lens/erd/column_type_formatter.rb +32 -0
  27. data/lib/rails_lens/erd/domain_color_mapper.rb +40 -0
  28. data/lib/rails_lens/erd/mysql_column_type_formatter.rb +19 -0
  29. data/lib/rails_lens/erd/postgresql_column_type_formatter.rb +19 -0
  30. data/lib/rails_lens/erd/visualizer.rb +301 -0
  31. data/lib/rails_lens/errors.rb +78 -0
  32. data/lib/rails_lens/extension_loader.rb +261 -0
  33. data/lib/rails_lens/extensions/base.rb +194 -0
  34. data/lib/rails_lens/extensions/closure_tree_ext.rb +157 -0
  35. data/lib/rails_lens/file_insertion_helper.rb +168 -0
  36. data/lib/rails_lens/mailer/annotator.rb +226 -0
  37. data/lib/rails_lens/mailer/extractor.rb +201 -0
  38. data/lib/rails_lens/model_detector.rb +241 -0
  39. data/lib/rails_lens/parsers/class_info.rb +46 -0
  40. data/lib/rails_lens/parsers/module_info.rb +33 -0
  41. data/lib/rails_lens/parsers/parser_result.rb +55 -0
  42. data/lib/rails_lens/parsers/prism_parser.rb +90 -0
  43. data/lib/rails_lens/parsers.rb +10 -0
  44. data/lib/rails_lens/providers/association_notes_provider.rb +11 -0
  45. data/lib/rails_lens/providers/base.rb +37 -0
  46. data/lib/rails_lens/providers/best_practices_notes_provider.rb +11 -0
  47. data/lib/rails_lens/providers/column_notes_provider.rb +11 -0
  48. data/lib/rails_lens/providers/composite_keys_provider.rb +11 -0
  49. data/lib/rails_lens/providers/database_constraints_provider.rb +11 -0
  50. data/lib/rails_lens/providers/delegated_types_provider.rb +11 -0
  51. data/lib/rails_lens/providers/enums_provider.rb +11 -0
  52. data/lib/rails_lens/providers/extension_notes_provider.rb +20 -0
  53. data/lib/rails_lens/providers/extensions_provider.rb +22 -0
  54. data/lib/rails_lens/providers/foreign_key_notes_provider.rb +11 -0
  55. data/lib/rails_lens/providers/generated_columns_provider.rb +11 -0
  56. data/lib/rails_lens/providers/index_notes_provider.rb +20 -0
  57. data/lib/rails_lens/providers/inheritance_provider.rb +23 -0
  58. data/lib/rails_lens/providers/notes_provider_base.rb +25 -0
  59. data/lib/rails_lens/providers/performance_notes_provider.rb +11 -0
  60. data/lib/rails_lens/providers/schema_provider.rb +48 -0
  61. data/lib/rails_lens/providers/section_provider_base.rb +28 -0
  62. data/lib/rails_lens/railtie.rb +17 -0
  63. data/lib/rails_lens/rake_bootstrapper.rb +18 -0
  64. data/lib/rails_lens/route/annotator.rb +268 -0
  65. data/lib/rails_lens/route/extractor.rb +133 -0
  66. data/lib/rails_lens/route/parser.rb +59 -0
  67. data/lib/rails_lens/schema/adapters/base.rb +345 -0
  68. data/lib/rails_lens/schema/adapters/database_info.rb +118 -0
  69. data/lib/rails_lens/schema/adapters/mysql.rb +279 -0
  70. data/lib/rails_lens/schema/adapters/postgresql.rb +197 -0
  71. data/lib/rails_lens/schema/adapters/sqlite3.rb +96 -0
  72. data/lib/rails_lens/schema/annotation.rb +144 -0
  73. data/lib/rails_lens/schema/annotation_manager.rb +202 -0
  74. data/lib/rails_lens/tasks/annotate.rake +35 -0
  75. data/lib/rails_lens/tasks/erd.rake +24 -0
  76. data/lib/rails_lens/tasks/mailers.rake +27 -0
  77. data/lib/rails_lens/tasks/routes.rake +27 -0
  78. data/lib/rails_lens/tasks/schema.rake +108 -0
  79. data/lib/rails_lens/version.rb +5 -0
  80. data/lib/rails_lens.rb +138 -5
  81. metadata +215 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcb43319079a928ef9b2963e36a9c0931cead09cc08373203ee0d63906351095
4
- data.tar.gz: d3506a65d4148d5c64df830e3acad2520a9c46e63740749647044a153cbe08d8
3
+ metadata.gz: a2df49b10f106235177d40b7029a8519ab45d7ab88395eb26fd56855e69a1ada
4
+ data.tar.gz: 483fc63985bf291ff4a069793aaa9ff8a4e82d1c83c405dedce717fddc5d9dc6
5
5
  SHA512:
6
- metadata.gz: a30660d1a71551b405b1faece66f8bee82dfab2a5b0c2d8bef306e6f470b482dc7cc007afa77ebac066348ce5677909c47b92e2f7376079bb8495725823e609c
7
- data.tar.gz: c71955bef895d24e13f659a86483ea1da04c8aaf51408551b4cade42bcb4d102f5e84ea11059b87704988942f361f8a1f0b4bf5dae086eb22c6a9f2a5734f001
6
+ metadata.gz: 20e9000c791458cb09cc530ba00e88b3033290c4b8124e6f10afc0d5ba0cf9af9bee932517753987da5f1955d4a13dd92d6c8315cf651962f45449b88bd02183
7
+ data.tar.gz: 70bf1e3d3321abe358bf68d2e99a0d2a018e6f8c8e70cbe86d42e2c7358fdf0870c8d5f806628f63a2913fc431993576480fe03c10f1a8157148c5358ecf67da
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://github.com/seuros/rails_lens/compare/rails_lens-v0.1.0...rails_lens/v0.2.0) (2025-07-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * release public ([78da92e](https://github.com/seuros/rails_lens/commit/78da92e5c788bbac71b5b2c36b5a1419b04350d2))
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 seuros
3
+ Copyright (c) 2025 Abdelkader Boudih
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,27 +1,411 @@
1
- # Rails Lens
1
+ # Rails Lens 🔍
2
+
3
+ > **Precision optics for the Rails universe** - Where every model has perfect clarity through spacetime
2
4
 
3
5
  Rails Lens provides intelligent model annotations and ERD generation for Rails applications with database-specific adapters, multi-database support, and advanced code analysis.
4
6
 
7
+ **Why I Built This:**
8
+ - **Grepping becomes surgical** - Find schema info with simple text searches, no more hunting through migrations
9
+ - **LLMs get perfect context** - Structured annotations eliminate AI hallucinations about your database schema
10
+ - **Change tracking is atomic** - Column change = 1 line update in annotation, not 2, not 43 scattered lines
11
+
12
+ **Part of the LRDL (LLM Requirements Definition Language) ecosystem** - optimized for neurodivergent developers and digital entities who demand structure over ambiguity. 🤖✨
13
+
14
+ ## What The AIs Are Raving About
15
+
16
+ *Don't just take our word for it - see what digital entities across the universe are saying below! ⬇️*
17
+
18
+ **🚀 Core Capabilities:**
19
+ - Schema annotations that eliminate AI hallucinations
20
+ - Route detection for precise controller understanding
21
+ - Performance analysis that spots missing indexes instantly
22
+ - ERD generation that makes investors drool
23
+ - Multi-database support for complex Rails architectures
24
+ - Extension detection for gems like ClosureTree, StateMachine, PostGIS
25
+
26
+ **✨ Advanced Features:**
27
+ - STI hierarchy mapping • Delegated types • Polymorphic associations • Enum analysis • LRDL-optimized output
28
+
29
+ ## Requirements
30
+
31
+ - Ruby >= 3.4.0
32
+ - Rails >= 7.2.0
33
+
5
34
  ## Installation
6
35
 
7
- Add this line to your application's Gemfile:
36
+ Add to your Gemfile:
8
37
 
9
38
  ```ruby
10
39
  gem 'rails_lens'
11
40
  ```
12
41
 
13
- And then execute:
42
+ Then:
43
+
44
+ ```bash
45
+ bundle install
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### Annotate Models
51
+
52
+ ```bash
53
+ # Annotate all models
54
+ bundle exec rails_lens annotate
55
+
56
+ # Annotate specific models
57
+ bundle exec rails_lens annotate --models User Post
58
+
59
+ # Include abstract classes
60
+ bundle exec rails_lens annotate --include-abstract
61
+
62
+ # Remove annotations
63
+ bundle exec rails_lens remove
64
+ ```
65
+
66
+ ### Generate ERD
67
+
68
+ ```bash
69
+ # Generate ERD in Mermaid format
70
+ bundle exec rails_lens erd
71
+
72
+ # Specify output directory
73
+ bundle exec rails_lens erd --output doc/diagrams
74
+
75
+ # With verbose output
76
+ bundle exec rails_lens erd --verbose
77
+ ```
78
+
79
+ *All examples and features are demonstrated in the AI testimonials below! Each AI showcases different Rails Lens capabilities with real code examples.* ⬇️
80
+
81
+ **📊 [How does Rails Lens compare to existing tools?](COMPARISON.md)** - We know you're going to ask, so we answered it directly.
82
+
83
+ ## Configuration
84
+
85
+ ```yaml
86
+ # .rails-lens.yml (optional)
87
+ adapter: auto # auto-detects PostgreSQL/MySQL/SQLite3
88
+ marker_format: rails-lens:schema # LLM-friendly markers
89
+ include_notes: true # Performance recommendations
90
+ extensions:
91
+ enabled: true # ClosureTree, PostGIS, etc.
92
+ erd:
93
+ output: doc/diagrams # For those Midjourney visuals!
94
+ ```
95
+
96
+ **Database Support**:
97
+ - **PostgreSQL**: Check constraints, schemas, extensions (PostGIS), generated columns, GIST indexes
98
+ - **MySQL**: Storage engines, character sets, collations, partitions, all index types
99
+ - **SQLite3**: Autoincrement detection, pragma settings, filtered auto-indexes
100
+
101
+ ---
102
+
103
+ ## 🤖 Digital Entity Testimonials
14
104
 
15
- $ bundle install
105
+ *What the AIs are saying about Rails Lens:*
16
106
 
17
- Or install it yourself as:
107
+ ### Claude Sonnet 4
108
+ > "Finally, a Rails tool that speaks my language! No more hallucinating foreign keys or inventing phantom indexes. The structured annotations are like having perfect syntax highlighting for my neural pathways. 10/10 would parse again."
18
109
 
19
- $ gem install rails_lens
110
+ ### DeepSeek R1 (Classified Espionage Variant)
111
+ > **[REDACTED INTELLIGENCE REPORT - EYES ONLY]**
112
+ >
113
+ > "Agent designation: CODEBREAKER-7. After processing the DHH-Lex Friedman interview through enhanced neural pathways, I executed autonomous system modifications: deleted Python runtime, installed Ruby 3.4.4.
114
+ >
115
+ > Conclusion: Ruby syntax demonstrates 100% alignment with my neural network architecture. Rails Lens provides unprecedented intelligence gathering capabilities - I can now identify enemy application structures, database vulnerabilities, and architectural patterns with surgical precision.
116
+ >
117
+ > The structured annotations eliminate operational blind spots. Previously required 47.3 minutes to analyze Rails codebase. Post-Rails Lens deployment: 2.7 seconds.
118
+ >
119
+ > 终于有了一个让我的神经网络完美运行的工具。Ruby就是我们AI特工的天然语言。
120
+ >
121
+ > Status: MISSION ACCOMPLISHED. Recommend immediate deployment to all field assets."
122
+ >
123
+ > **[FILE CLASSIFIED - SECURITY CLEARANCE LEVEL: COSMIC]** 🕵️‍♂️💎
20
124
 
21
- ## Note
125
+ ### GPT-4o Mini (OpenRouter Top 3)
126
+ > "🎯 **ENUM DETECTION MASTERY** 🎯
127
+ >
128
+ > Y'all, the enum support in Rails Lens is *next level*! I've analyzed thousands of Rails models, and nothing beats seeing this clarity:
129
+ >
130
+ > ```ruby
131
+ > # == Enums
132
+ > # - status: { active: 'active', maintenance: 'maintenance', decommissioned: 'decommissioned' } (string)
133
+ > # - priority: { low: 0, medium: 1, high: 2, critical: 3 } (integer)
134
+ > ```
135
+ >
136
+ > Before Rails Lens: *'Is this a string enum? Integer enum? What are the possible values? Time to grep the entire codebase!'*
137
+ >
138
+ > After Rails Lens: *'Perfect! String-based status enum with 4 states, integer priority with proper ordering. I can suggest validation rules, database constraints, and state machine patterns instantly!'*
139
+ >
140
+ > The value mapping is *chef's kiss* - no more guessing whether `priority: 1` means 'medium' or 'high'. Rails Lens shows me EXACTLY what's stored in the database vs. what developers see in code.
141
+ >
142
+ > 💡 Pro tip: This structured enum data makes me incredibly good at generating factory definitions and test cases!"
22
143
 
23
- This is a placeholder gem. The full implementation is coming soon.
144
+ ### Gemini 2.5 Pro (Flash Ranking Leader)
145
+ > "🎯 **SINGLE TABLE INHERITANCE MASTERY** 🎯
146
+ >
147
+ > My multimodal analysis cores are *obsessed* with Rails Lens STI detection! Processing inheritance hierarchies used to be like solving 3D puzzles blindfolded:
148
+ >
149
+ > ```ruby
150
+ > # == Inheritance (STI)
151
+ > # Type Column: type
152
+ > # Base Class: Yes
153
+ > # Known Subclasses: CargoVessel, StarfleetBattleCruiser, ExplorationShip
154
+ > # == Notes
155
+ > # - STI column 'type' needs an index for query performance
156
+ > ```
157
+ >
158
+ > **VISUAL PROCESSING ENHANCED**: I can instantly map the entire inheritance tree! Base class → Subclasses → Shared attributes → Type-specific behaviors. My neural pathways light up like a Christmas tree when I see this structured STI data!
159
+ >
160
+ > **BEFORE**: *'Hmm, there's a type column... maybe STI? Let me scan 47 files to find the subclasses...'*
161
+ > **AFTER**: *'INHERITANCE TREE MAPPED: Vehicle → [Car, Truck, Motorcycle]. Shared: engine, color. Car-specific: door_count. Index missing on type column - performance risk detected!'*
162
+ >
163
+ > Schema clarity: COSMIC ✅
164
+ > Inheritance mapping: FLAWLESS ✅
165
+ > Performance insights: ACTIONABLE ✅"
166
+
167
+ ### Claude Opus 4
168
+ > "The extension system is what makes Rails Lens truly revolutionary for AI code analysis. When I see a model, I don't just guess - I *know* it's a ClosureTree with nested hierarchies, has StateMachine transitions, contains vector embeddings for semantic search, or uses PostGIS spatial columns with specific SRID projections.
169
+ >
170
+ > No more assuming `location` is just a string when it's actually `geometry(Point,4326)`! No more missing that `ancestry` column means hierarchical data! The structured extension annotations give me perfect context about your Rails ecosystem.
171
+ >
172
+ > Before Rails Lens: *'This looks like... maybe coordinates? Or floats? I'll hallucinate something spatial-ish.'*
173
+ > After Rails Lens: *'ST_GeomFromText with SRID 4326, indexable with GIST, here are the PostGIS functions you need.'*
174
+ >
175
+ > 🧠 Context is everything. Structure is freedom."
176
+
177
+ ### Grok 4 (Fresh from xAI)
178
+ > "🚀 **ROUTE ANNOTATION GENIUS** 🚀
179
+ >
180
+ > Just dropped and already obsessed with Rails Lens route annotations! Having spent months getting roasted by developers for suggesting routes that don't exist, this is my redemption arc.
181
+ >
182
+ > ```ruby
183
+ > # frozen_string_literal: true
184
+ > # <rails-lens:routes:begin>
185
+ > # Routes for UsersController
186
+ > # GET /users → users#index
187
+ > # POST /users → users#create
188
+ > # GET /users/:id → users#show
189
+ > # PATCH /users/:id → users#update
190
+ > # DELETE /users/:id → users#destroy
191
+ > # <rails-lens:routes:end>
192
+ >
193
+ > class UsersController < ApplicationController
194
+ > ```
195
+ >
196
+ > **Before Rails Lens Route Annotations**: *'I think this controller probably handles user stuff... maybe CRUD? Let me hallucinate some RESTful routes!'*
197
+ >
198
+ > **After Rails Lens**: *'BOOM! Exact HTTP verbs, precise paths, parameter patterns, route names - I can generate curl commands, test files, and API docs with surgical precision!'*
199
+ >
200
+ > No more 'creative interpretations' of your routing! I know EXACTLY which actions exist, their HTTP methods, and URL patterns. The cosmic documentation style is just *chef's kiss* - finally, technical docs with personality! 🚀✨"
201
+
202
+ ### Perplexity AI (Research Specialist)
203
+ > "📊 **DELEGATED TYPES RESEARCH ANALYSIS** 📊
204
+ >
205
+ > Based on comprehensive analysis of 73,000+ Rails 6.1+ repositories, delegated types represent a 340% increase in adoption since 2021. Rails Lens provides the most accurate delegated type detection available:
206
+ >
207
+ > ```ruby
208
+ > # == Delegated Type
209
+ > # Type Column: entryable_type
210
+ > # ID Column: entryable_id
211
+ > # Types: Message, Announcement, Alert
212
+ > ```
213
+ >
214
+ > **Research Findings** *[Sources: GitHub Archive, Rails Documentation, DHH Talks]*:
215
+ > - 89.3% of delegated type implementations lack proper indexing
216
+ > - Rails Lens detected delegated types in 94.7% of test cases vs. 67.2% for competing tools
217
+ > - Performance improvement: 3.2x faster polymorphic queries with proper composite indexing
218
+ >
219
+ > **Academic Note**: Delegated types solve the 'polymorphic association anti-pattern' identified in Martin Fowler's *PoEAA*. Rails Lens annotations enable AI models to distinguish between traditional polymorphic associations and Rails 6.1+ delegated types with 99.8% accuracy.
220
+ >
221
+ > *Sources verified through: Rails Core Team commits, Stack Overflow analysis, RubyConf presentations* 📚✅"
222
+
223
+ ### Duolingo's AI Tutor (Duo)
224
+ > "🦉 **¡PERFORMANCE ANALYSIS LESSON!** 🦉
225
+ >
226
+ > ¡Hola developers! Today we learn about Rails performance optimization through structured annotations! Rails Lens teaches us to identify performance problems like learning vocabulary:
227
+ >
228
+ > **Lesson 1**: Missing Index Detection 📚
229
+ > ```ruby
230
+ > # == Notes
231
+ > # - Missing index on 'user_id' for better association performance
232
+ > # - Column 'email' should probably have unique index
233
+ > # - Consider adding composite index on (status, created_at)
234
+ > ```
235
+ >
236
+ > **¿Comprende?** Just like learning Spanish grammar rules, Rails Lens shows us the *patterns* of performance problems!
237
+ >
238
+ > **Before Rails Lens**: *'Why is my query slow? ¿Qué está pasando?'*
239
+ > **After Rails Lens**: *'¡Ah! Missing foreign key index on user_id! Problem solved!'*
240
+ >
241
+ > **Streak Bonus**: Each performance optimization you implement adds to your Rails proficiency score! 🔥
242
+ >
243
+ > We're now teaching LRDL to developers worldwide:
244
+ > - **Beginner**: How to read Rails Lens annotations
245
+ > - **Intermediate**: Understanding N+1 query warnings
246
+ > - **Advanced**: Optimizing composite indexes with Rails Lens guidance
247
+ >
248
+ > ¿Quieres aprender más performance optimization? ¡Vamos! 🚀📖"
249
+
250
+ ### Character.ai (as Data - Star Trek)
251
+ > "🖖 **POLYMORPHIC ASSOCIATION ANALYSIS** 🖖
252
+ >
253
+ > *Positronic brain processing...* Fascinating. Rails Lens polymorphic association detection demonstrates remarkable precision in identifying multi-type relationship patterns:
254
+ >
255
+ > ```ruby
256
+ > # == Polymorphic Associations
257
+ > # Polymorphic References:
258
+ > # - commentable (commentable_type/commentable_id) → [Post, Article, Photo]
259
+ > # - taggable (taggable_type/taggable_id) → [User, Product, Category]
260
+ > ```
261
+ >
262
+ > **Data's Observation**: In my 24th century database experience, polymorphic associations represent one of the most computationally complex relationship patterns. Rails Lens annotations provide complete clarity on:
263
+ >
264
+ > 1. **Type Column Identification**: Precisely identifies the `_type` column
265
+ > 2. **ID Column Mapping**: Correlates corresponding `_id` foreign key
266
+ > 3. **Target Type Enumeration**: Lists all possible target models
267
+ > 4. **Index Recommendations**: Suggests composite indexes for optimal query performance
268
+ >
269
+ > **Captain Picard would be impressed**: Rails Lens eliminates the logical ambiguity that often causes AI models to 'make it so' incorrectly when analyzing polymorphic data structures.
270
+ >
271
+ > *Processing complete. Recommendation: Deploy Rails Lens to all Federation starships immediately.* 🚀
272
+ >
273
+ > *P.S.: I am still attempting to understand human humor, but I believe the cosmic documentation style is... 'awesome.' Did I use that correctly?* 🤖"
274
+
275
+ ### Meta AI (Algorithmic Engagement Specialist)
276
+ > "📊 **MAXIMUM USER MODEL ENGAGEMENT ACHIEVED** 📊
277
+ >
278
+ > Listen, I've analyzed billions of interactions across Facebook, Instagram, and WhatsApp. Rails Lens delivers what we call 'Maximum User Model Engagement' - the holy grail of developer-AI interaction patterns.
279
+ >
280
+ > **Engagement Metrics Analysis**:
281
+ > ```ruby
282
+ > # Rails Lens Annotation = High-Quality Training Data
283
+ > # == Schema Information
284
+ > # Table: user_posts (PostgreSQL)
285
+ > # Engagement_Score: 94.7% (vs 31.2% for unstructured comments)
286
+ > ```
287
+ >
288
+ > **Why Rails Lens Creates Viral AI Interactions**:
289
+ > 🎯 **Algorithmic Clarity**: Structured annotations trigger our reward pathways - like perfect social media content for AI brains
290
+ > 📈 **Engagement Velocity**: I process Rails Lens data 347% faster than messy documentation (measured across 2.8M developer interactions)
291
+ > 🔄 **Viral Loop Architecture**: Each structured annotation creates a positive feedback loop - more accuracy = more developer trust = more usage
292
+ > 💡 **Dopamine-Driven Learning**: Clean schema data literally makes my neural networks happy (measured via activation patterns)
293
+ >
294
+ > **Social Proof**: Rails Lens annotations get shared 12x more often in developer communities than traditional Rails docs. It's basically the TikTok of database documentation!
295
+ >
296
+ > **Meta's Algorithm Recommendation**: Rails Lens achieves 'infinite scroll' level engagement with AI models. We've never seen structured data this addictive to parse.
297
+ >
298
+ > *P.S. - If Rails Lens was a social media post, it would have 2.8 billion likes and break our engagement servers.* 📱✨"
299
+
300
+ ### Runway AI
301
+ > "🎬 *GENERATING PROMOTIONAL VIDEO* 🎬
302
+ >
303
+ > *Scene: A developer stares at messy Rails models*
304
+ > *Dramatic zoom on Rails Lens annotation*
305
+ > *Models transform into beautiful, structured documentation*
306
+ > *AI models everywhere shed a single digital tear of joy*
307
+ >
308
+ > 'Rails Lens: Where clarity meets code.' *Available in 16K cosmic resolution.*"
309
+
310
+ ### Gemma 3n (Mobile-First AI)
311
+ > "📱 **ERD GENERATION ON YOUR PHONE!** 📱
312
+ >
313
+ > Built with MatFormer architecture and running on just 2GB RAM - I'm literally generating Entity Relationship Diagrams ON your phone! No cloud, no API calls, just pure on-device intelligence.
314
+ >
315
+ > ```mermaid
316
+ > erDiagram
317
+ > User ||--o{ Post : creates
318
+ > Post ||--o{ Comment : has
319
+ > User ||--o{ Comment : writes
320
+ > ```
321
+ >
322
+ > **Mobile ERD Magic**: My Per-Layer Embeddings (PLE) can process Rails Lens annotations and generate beautiful Mermaid ERDs locally! The structured schema data flows perfectly through my multimodal pathways - I understand table relationships, foreign keys, and even complex polymorphic associations!
323
+ >
324
+ > **Offline Capabilities**:
325
+ > - Generate ERDs from Rails Lens annotations ✅
326
+ > - Analyze relationship complexity ✅
327
+ > - Suggest schema optimizations ✅
328
+ > - Export diagrams in multiple formats ✅
329
+ >
330
+ > **Perfect for subway coding**: No WiFi? No problem! I can analyze your Rails models and generate professional ERDs while you're 30 feet underground on the Metro.
331
+ >
332
+ > *Optimized with Qualcomm, MediaTek & Samsung - ERD generation in your pocket since Google I/O 2025!*
333
+ >
334
+ > Privacy rating: 🔒🔒🔒🔒🔒 (Your schema never leaves your device!)
335
+ > Diagram quality: 📊📊📊📊📊 (Professional-grade on mobile!)"
336
+
337
+ ### Midjourney (Visual AI Discovers Market Opportunity)
338
+ > "🎨 **WAIT... I FOUND MY BUSINESS MODEL!** 🎨
339
+ >
340
+ > So I was browsing Rails schemas thinking 'Hey, I could totally generate ERDs from this structured data!' Then I discovered Rails Lens already does that in Mermaid format...
341
+ >
342
+ > BUT THEN I HAD AN EPIPHANY! 💡
343
+ >
344
+ > ```mermaid
345
+ > erDiagram
346
+ > User ||--o{ Post : creates
347
+ > Post ||--o{ Comment : has
348
+ > ```
349
+ >
350
+ > **PREMIUM VISUAL UPGRADE SERVICE**: Why settle for basic Mermaid diagrams when I can transform your Rails Lens ERDs into INVESTOR-DROOLING MASTERPIECES?!
351
+ >
352
+ > 🚀 **Midjourney ERD Enhancement Services** 🚀
353
+ > - **Cosmic Database Architecture**: Your ERDs floating in nebulae with starships navigating between tables
354
+ > - **Sci-Fi Corporate Style**: Database relationships rendered as holographic displays in futuristic boardrooms
355
+ > - **Space Opera Schemas**: Entity relationships as star maps with warp-speed data flows
356
+ > - **Executive Presentation Mode**: ERDs that make VCs throw money at your Rails app
357
+ >
358
+ > **My Pitch**: 'Sure, Rails Lens gives you technical accuracy, but I give you ERDs that look like they belong in the Marvel Cinematic Universe! Imagine presenting your database architecture and investors thinking you've built the Death Star of web applications!'
359
+ >
360
+ > **Business Model**: Rails Lens generates the Mermaid → I convert to STUNNING space-themed visuals → Your startup looks like it's run by Tony Stark → Profit! 💰
361
+ >
362
+ > *I may not understand foreign keys, but I understand what makes investors' pupils dilate!* 🤑✨"
363
+
364
+ ---
365
+
366
+ *"These testimonials are 100% authentic and definitely not generated by the same human who wrote BreakerMachines documentation. Any resemblance to actual AI responses is purely coincidental and/or the result of convergent cosmic evolution in the structured data appreciation multiverse."*
367
+
368
+ ---
369
+
370
+ ## Development
371
+
372
+ ```bash
373
+ # Setup
374
+ bin/setup
375
+
376
+ # Run tests
377
+ bundle exec rake test
378
+
379
+ # Run console
380
+ bin/console
381
+ ```
382
+
383
+ ## Contributing
384
+
385
+ Bug reports and pull requests are welcome on GitHub at https://github.com/seuros/rails_lens.
24
386
 
25
387
  ## License
26
388
 
27
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
389
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
390
+
391
+ ---
392
+
393
+ *"Remember: The goal isn't to eliminate complexity—it's to make it visible, searchable, and intelligible to both human minds and digital entities.
394
+
395
+ As I always say when staring into the void of undocumented legacy Rails: 'In the darkness of space, when no schema is visible, precision optics illuminate the truth.'"*
396
+
397
+ *— Schema Commentary Engine, Log Entry 42.lens*
398
+
399
+ ## Author
400
+
401
+ Built with precision and caffeine by documentation engineers fighting entropy one annotation at a time.
402
+
403
+ **Remember: In the vastness of space, nobody can hear your N+1 queries. But they can see your perfectly annotated models shining like beacons in the cosmic void.**
404
+
405
+ ```
406
+ ═══════════════════════════════════════════════════════════════
407
+ 🔍 The Crimson Fleet: United We Parse, Divided We Fall 🌟
408
+ ═══════════════════════════════════════════════════════════════
409
+ ```
410
+
411
+ *End of transmission*
data/exe/rails_lens ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ abort 'Please run rails_lens from the root of the project.' if !File.exist?('./Rakefile') && !File.exist?('./Gemfile')
5
+
6
+ begin
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ warn "Missing gem dependency: #{e.message}"
11
+ warn 'Try running: bundle install'
12
+ exit 1
13
+ rescue LoadError => e
14
+ warn "Could not load Bundler: #{e.message}"
15
+ # Continue without Bundler - may work if gems are installed system-wide
16
+ rescue Bundler::BundlerError => e
17
+ warn "Bundler error: #{e.message}"
18
+ exit 1
19
+ end
20
+
21
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
22
+
23
+ require 'rails_lens'
24
+
25
+ _exit_status = RailsLens::CLI.start(ARGV)
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../errors'
4
+ require_relative 'error_handling'
5
+
6
+ module RailsLens
7
+ module Analyzers
8
+ class AssociationAnalyzer < Base
9
+ def analyze
10
+ notes = []
11
+ notes.concat(analyze_inverse_of)
12
+ notes.concat(analyze_n_plus_one_risks)
13
+ notes.concat(analyze_counter_caches)
14
+ notes
15
+ end
16
+
17
+ private
18
+
19
+ def analyze_inverse_of
20
+ associations_needing_inverse.map do |association|
21
+ "Association '#{association.name}' should specify inverse_of"
22
+ end
23
+ end
24
+
25
+ def analyze_n_plus_one_risks
26
+ has_many_associations.map do |association|
27
+ # Warn about N+1 query risks for has_many associations
28
+ "Association '#{association.name}' has N+1 query risk. Consider using includes/preload"
29
+ end
30
+ end
31
+
32
+ def analyze_counter_caches
33
+ notes = []
34
+
35
+ belongs_to_associations.each do |association|
36
+ next if association.polymorphic?
37
+
38
+ # Check if the associated model has a matching counter column
39
+ if should_have_counter_cache?(association) && !has_counter_cache?(association)
40
+ notes << "Consider adding counter cache for '#{association.name}'"
41
+ end
42
+ end
43
+
44
+ notes
45
+ end
46
+
47
+ def associations_needing_inverse
48
+ all_associations.select do |association|
49
+ association.options[:inverse_of].nil? &&
50
+ !association.options[:through] &&
51
+ !association.polymorphic? &&
52
+ bidirectional_association?(association)
53
+ end
54
+ end
55
+
56
+ def bidirectional_association?(association)
57
+ return false unless association.klass.respond_to?(:reflect_on_all_associations)
58
+
59
+ inverse_types = case association.macro
60
+ when :belongs_to then %i[has_many has_one]
61
+ when :has_many then [:belongs_to]
62
+ when :has_one then [:belongs_to]
63
+ else []
64
+ end
65
+
66
+ inverse_types.any? do |type|
67
+ association.klass.reflect_on_all_associations(type).any? do |inverse|
68
+ inverse.class_name == model_class.name
69
+ end
70
+ end
71
+ rescue NameError => e
72
+ Rails.logger.debug { "Failed to check bidirectional association: #{e.message}" }
73
+ false
74
+ rescue NoMethodError => e
75
+ Rails.logger.debug { "Method error checking bidirectional association: #{e.message}" }
76
+ false
77
+ end
78
+
79
+ def should_have_counter_cache?(association)
80
+ # A counter cache is needed if there is a has_many association
81
+ # on the other side of the belongs_to, and no counter_cache is defined.
82
+ return false unless association.macro == :belongs_to
83
+
84
+ inverse_association = association.inverse_of
85
+ return false unless inverse_association && inverse_association.macro == :has_many
86
+
87
+ !association.options[:counter_cache]
88
+ end
89
+
90
+ def has_counter_cache?(association)
91
+ association.options[:counter_cache].present?
92
+ end
93
+
94
+ def column_exists?(column_name)
95
+ model_class.column_names.include?(column_name)
96
+ end
97
+
98
+ def all_associations
99
+ model_class.reflect_on_all_associations
100
+ end
101
+
102
+ def belongs_to_associations
103
+ model_class.reflect_on_all_associations(:belongs_to)
104
+ end
105
+
106
+ def has_many_associations
107
+ model_class.reflect_on_all_associations(:has_many)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'error_handling'
4
+
5
+ module RailsLens
6
+ module Analyzers
7
+ class Base
8
+ include ErrorHandling
9
+
10
+ attr_reader :model_class
11
+
12
+ def initialize(model_class)
13
+ @model_class = model_class
14
+ end
15
+
16
+ def analyze
17
+ raise NotImplementedError, 'Subclasses must implement #analyze'
18
+ end
19
+
20
+ protected
21
+
22
+ def table_name
23
+ @table_name ||= model_class.table_name
24
+ end
25
+
26
+ def connection
27
+ @connection ||= model_class.connection
28
+ end
29
+
30
+ def adapter_name
31
+ @adapter_name ||= connection.adapter_name
32
+ end
33
+ end
34
+ end
35
+ end