rails_lens 0.2.10 → 0.2.11
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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +14 -0
- data/lib/rails_lens/cli.rb +9 -0
- data/lib/rails_lens/commands.rb +113 -0
- data/lib/rails_lens/configuration.rb +73 -78
- data/lib/rails_lens/version.rb +1 -1
- data/lib/rails_lens.rb +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db0b169f8f397031eecb4ff3b50a5047f12cf1bc2c1d0929a674f3b0827c7c91
|
|
4
|
+
data.tar.gz: 5be691de8fce3047e5226f7a5d0e9f12a9410609d3de3a91f43d657dd287d6c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c40baa22b05b1c652d3fd3fb617a4d81c2d5349d6aa550dc49c1a7bbd3dfdd74b576151848dc6430e6ad01ff76705000892129b5990a432429dc3a60de4b3d4
|
|
7
|
+
data.tar.gz: 49900c83dd33dd65ccf0bf0221c130b6363a35d14eafa25403930d0990e445e94cb60d0344b0e0988485a2d4e0acdf165204a0930620b8e8dbf218486a81704a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.11](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.10...rails_lens/v0.2.11) (2025-11-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add install command for automatic post-migration annotation ([#28](https://github.com/seuros/rails_lens/issues/28)) ([873fcdc](https://github.com/seuros/rails_lens/commit/873fcdcb4ca481273f71068824d066557f3cc38b))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* replace deprecated ActiveSupport::Configurable and update CI to Rails 8.1 ([#26](https://github.com/seuros/rails_lens/issues/26)) ([b540214](https://github.com/seuros/rails_lens/commit/b540214afd25e0313ee2772e6c65d81bae68cb64))
|
|
14
|
+
|
|
3
15
|
## [0.2.10](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.9...rails_lens/v0.2.10) (2025-10-17)
|
|
4
16
|
|
|
5
17
|
|
data/README.md
CHANGED
|
@@ -117,6 +117,20 @@ bundle install
|
|
|
117
117
|
|
|
118
118
|
## Usage
|
|
119
119
|
|
|
120
|
+
### Quick Setup (Recommended)
|
|
121
|
+
|
|
122
|
+
Install automatic annotation after migrations:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
bundle exec rails_lens install
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This creates `lib/tasks/rails_lens.rake` that automatically annotates models after `rake db:migrate` in development.
|
|
129
|
+
|
|
130
|
+
**Configuration:**
|
|
131
|
+
- `AUTO_ANNOTATE=false` - Disable auto-annotation
|
|
132
|
+
- `RAILS_LENS_ENV=test,development` - Environments where it runs (default: development only)
|
|
133
|
+
|
|
120
134
|
### Annotate Models
|
|
121
135
|
|
|
122
136
|
```bash
|
data/lib/rails_lens/cli.rb
CHANGED
|
@@ -124,6 +124,15 @@ module RailsLens
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
desc 'install', 'Install Rails Lens rake tasks for automatic annotation'
|
|
128
|
+
option :force, type: :boolean, desc: 'Overwrite existing rake task file'
|
|
129
|
+
def install
|
|
130
|
+
with_error_handling do
|
|
131
|
+
commands = Commands.new(self)
|
|
132
|
+
commands.install(options)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
127
136
|
private
|
|
128
137
|
|
|
129
138
|
def setup_environment
|
data/lib/rails_lens/commands.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
3
5
|
module RailsLens
|
|
4
6
|
# Handles the actual execution of CLI commands
|
|
5
7
|
class Commands
|
|
@@ -160,5 +162,116 @@ module RailsLens
|
|
|
160
162
|
output.say 'Available: show, set, reset'
|
|
161
163
|
end
|
|
162
164
|
end
|
|
165
|
+
|
|
166
|
+
def install(options = {})
|
|
167
|
+
output.say 'Installing Rails Lens rake tasks...', :blue
|
|
168
|
+
|
|
169
|
+
# Determine Rails root
|
|
170
|
+
rails_root = if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
|
|
171
|
+
Rails.root.to_s
|
|
172
|
+
else
|
|
173
|
+
Dir.pwd
|
|
174
|
+
end
|
|
175
|
+
tasks_dir = File.join(rails_root, 'lib', 'tasks')
|
|
176
|
+
rake_file = File.join(tasks_dir, 'rails_lens.rake')
|
|
177
|
+
|
|
178
|
+
# Check if file exists
|
|
179
|
+
if File.exist?(rake_file) && !options[:force]
|
|
180
|
+
output.say 'Rails Lens rake task already exists at lib/tasks/rails_lens.rake', :yellow
|
|
181
|
+
output.say 'Use --force to overwrite', :yellow
|
|
182
|
+
return { installed: false, path: rake_file }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Create lib/tasks directory if it doesn't exist
|
|
186
|
+
FileUtils.mkdir_p(tasks_dir) unless Dir.exist?(tasks_dir)
|
|
187
|
+
|
|
188
|
+
# Write the rake task
|
|
189
|
+
File.write(rake_file, rake_task_template)
|
|
190
|
+
|
|
191
|
+
output.say "Created rake task at #{rake_file}", :green
|
|
192
|
+
output.say '', :reset
|
|
193
|
+
output.say 'The following task has been installed:', :blue
|
|
194
|
+
output.say ' • rails_lens:annotate - Annotate models after migrations', :green
|
|
195
|
+
output.say '', :reset
|
|
196
|
+
output.say 'Configuration options in lib/tasks/rails_lens.rake:', :blue
|
|
197
|
+
output.say ' • AUTO_ANNOTATE (default: true in development)', :cyan
|
|
198
|
+
output.say ' • RAILS_LENS_ENV (default: development)', :cyan
|
|
199
|
+
output.say '', :reset
|
|
200
|
+
output.say 'Disable auto-annotation:', :blue
|
|
201
|
+
output.say ' export AUTO_ANNOTATE=false', :cyan
|
|
202
|
+
|
|
203
|
+
{ installed: true, path: rake_file }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
private
|
|
207
|
+
|
|
208
|
+
def rake_task_template
|
|
209
|
+
<<~RAKE
|
|
210
|
+
# frozen_string_literal: true
|
|
211
|
+
|
|
212
|
+
# Rails Lens automatic annotation task
|
|
213
|
+
# Generated by: rails_lens install
|
|
214
|
+
#
|
|
215
|
+
# This task automatically annotates models after running migrations.
|
|
216
|
+
# It only runs in development by default to avoid slowing down CI/production deploys.
|
|
217
|
+
#
|
|
218
|
+
# Environment variables:
|
|
219
|
+
# AUTO_ANNOTATE=false - Disable automatic annotation
|
|
220
|
+
# RAILS_LENS_ENV=test,development - Environments where annotation runs
|
|
221
|
+
|
|
222
|
+
namespace :rails_lens do
|
|
223
|
+
desc 'Annotate models with schema information'
|
|
224
|
+
task annotate: :environment do
|
|
225
|
+
# Check if auto-annotation is enabled
|
|
226
|
+
auto_annotate = ENV.fetch('AUTO_ANNOTATE', 'true')
|
|
227
|
+
if auto_annotate == 'false'
|
|
228
|
+
puts 'Rails Lens: Auto-annotation disabled (AUTO_ANNOTATE=false)'
|
|
229
|
+
next
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Check if we're in an allowed environment
|
|
233
|
+
allowed_envs = ENV.fetch('RAILS_LENS_ENV', 'development').split(',').map(&:strip)
|
|
234
|
+
unless allowed_envs.include?(Rails.env)
|
|
235
|
+
puts "Rails Lens: Skipping annotation in \#{Rails.env} environment"
|
|
236
|
+
next
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
puts 'Rails Lens: Annotating models...'
|
|
240
|
+
begin
|
|
241
|
+
# Use RailsLens directly if available
|
|
242
|
+
if defined?(RailsLens)
|
|
243
|
+
results = RailsLens::Schema::AnnotationManager.annotate_all
|
|
244
|
+
puts "Rails Lens: Annotated \#{results[:annotated].length} models"
|
|
245
|
+
puts "Rails Lens: Skipped \#{results[:skipped].length} models" if results[:skipped].any?
|
|
246
|
+
else
|
|
247
|
+
# Fallback to CLI
|
|
248
|
+
system('bundle exec rails_lens annotate --quiet')
|
|
249
|
+
end
|
|
250
|
+
rescue StandardError => e
|
|
251
|
+
warn "Rails Lens: Annotation failed: \#{e.message}"
|
|
252
|
+
warn 'Rails Lens: Set AUTO_ANNOTATE=false to disable auto-annotation'
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Hook into db:migrate
|
|
258
|
+
if Rake::Task.task_defined?('db:migrate')
|
|
259
|
+
Rake::Task['db:migrate'].enhance do
|
|
260
|
+
Rake::Task['rails_lens:annotate'].invoke if defined?(Rails)
|
|
261
|
+
rescue StandardError => e
|
|
262
|
+
warn "Rails Lens hook failed: \#{e.message}"
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Hook into db:rollback
|
|
267
|
+
if Rake::Task.task_defined?('db:rollback')
|
|
268
|
+
Rake::Task['db:rollback'].enhance do
|
|
269
|
+
Rake::Task['rails_lens:annotate'].invoke if defined?(Rails)
|
|
270
|
+
rescue StandardError => e
|
|
271
|
+
warn "Rails Lens hook failed: \#{e.message}"
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
RAKE
|
|
275
|
+
end
|
|
163
276
|
end
|
|
164
277
|
end
|
|
@@ -1,93 +1,88 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RailsLens
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Config
|
|
5
|
+
attr_accessor :verbose, :debug, :raise_on_error, :logger,
|
|
6
|
+
:annotations, :erd, :schema, :extensions, :routes, :mailers
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
def initialize
|
|
9
|
+
@verbose = false
|
|
10
|
+
@debug = false
|
|
11
|
+
@raise_on_error = false
|
|
12
|
+
@logger = nil
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
@annotations = {
|
|
15
|
+
position: :before,
|
|
16
|
+
format: :rdoc
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
@erd = {
|
|
20
|
+
output_dir: 'doc/erd',
|
|
21
|
+
orientation: 'TB',
|
|
22
|
+
theme: true,
|
|
23
|
+
default_colors: %w[
|
|
24
|
+
lightblue
|
|
25
|
+
lightcoral
|
|
26
|
+
lightgreen
|
|
27
|
+
lightyellow
|
|
28
|
+
plum
|
|
29
|
+
lightcyan
|
|
30
|
+
lightgray
|
|
31
|
+
]
|
|
32
|
+
}
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
plum
|
|
35
|
-
lightcyan
|
|
36
|
-
lightgray
|
|
37
|
-
]
|
|
34
|
+
@schema = {
|
|
35
|
+
adapter: :auto,
|
|
36
|
+
include_notes: true,
|
|
37
|
+
exclude_tables: nil, # Will use ActiveRecord::SchemaDumper.ignore_tables if nil
|
|
38
|
+
format_options: {
|
|
39
|
+
show_defaults: true,
|
|
40
|
+
show_comments: true,
|
|
41
|
+
show_foreign_keys: true,
|
|
42
|
+
show_indexes: true,
|
|
43
|
+
show_check_constraints: true
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
}
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
show_check_constraints: true
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
end
|
|
47
|
+
@extensions = {
|
|
48
|
+
enabled: true,
|
|
49
|
+
autoload: true,
|
|
50
|
+
interface_version: '1.0',
|
|
51
|
+
ignore: [],
|
|
52
|
+
custom_paths: [],
|
|
53
|
+
error_reporting: :warn, # :silent, :warn, :verbose
|
|
54
|
+
fail_safe_mode: true, # Continue processing if extensions fail
|
|
55
|
+
track_health: false # Track extension success/failure rates
|
|
56
|
+
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
error_reporting: :warn, # :silent, :warn, :verbose
|
|
64
|
-
fail_safe_mode: true, # Continue processing if extensions fail
|
|
65
|
-
track_health: false # Track extension success/failure rates
|
|
66
|
-
}
|
|
67
|
-
end
|
|
58
|
+
@routes = {
|
|
59
|
+
enabled: true,
|
|
60
|
+
include_defaults: true,
|
|
61
|
+
include_constraints: true,
|
|
62
|
+
pattern: '**/*_controller.rb',
|
|
63
|
+
exclusion_pattern: 'vendor/**/*_controller.rb'
|
|
64
|
+
}
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
@mailers = {
|
|
67
|
+
enabled: true,
|
|
68
|
+
include_templates: true,
|
|
69
|
+
include_delivery_methods: true,
|
|
70
|
+
include_variables: true,
|
|
71
|
+
include_locales: true,
|
|
72
|
+
include_defaults: true,
|
|
73
|
+
pattern: '**/*_mailer.rb',
|
|
74
|
+
exclusion_pattern: 'vendor/**/*_mailer.rb'
|
|
75
|
+
}
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
include_defaults: true,
|
|
87
|
-
pattern: '**/*_mailer.rb',
|
|
88
|
-
exclusion_pattern: 'vendor/**/*_mailer.rb'
|
|
89
|
-
}
|
|
90
|
-
end
|
|
79
|
+
module Configuration
|
|
80
|
+
def config
|
|
81
|
+
@config ||= Config.new
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def configure
|
|
85
|
+
yield config if block_given?
|
|
91
86
|
end
|
|
92
87
|
end
|
|
93
88
|
end
|
data/lib/rails_lens/version.rb
CHANGED
data/lib/rails_lens.rb
CHANGED
|
@@ -4,7 +4,6 @@ require 'zeitwerk'
|
|
|
4
4
|
require 'rails'
|
|
5
5
|
require 'active_record'
|
|
6
6
|
require 'active_support'
|
|
7
|
-
require 'active_support/configurable'
|
|
8
7
|
require 'thor'
|
|
9
8
|
require 'ostruct'
|
|
10
9
|
|
|
@@ -29,8 +28,7 @@ require_relative 'rails_lens/cli'
|
|
|
29
28
|
require_relative 'rails_lens/configuration'
|
|
30
29
|
|
|
31
30
|
module RailsLens
|
|
32
|
-
|
|
33
|
-
include Configuration
|
|
31
|
+
extend Configuration
|
|
34
32
|
|
|
35
33
|
class << self
|
|
36
34
|
def logger
|