rails_lens 0.2.9 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7267c551ada38ab296fd1c45e75973f55d77d6aa6a3c7e8e36f672008780202
4
- data.tar.gz: da563824b522ce15a6980630211b2a32b55e3ecacb3595695af3fc7661e4e158
3
+ metadata.gz: db0b169f8f397031eecb4ff3b50a5047f12cf1bc2c1d0929a674f3b0827c7c91
4
+ data.tar.gz: 5be691de8fce3047e5226f7a5d0e9f12a9410609d3de3a91f43d657dd287d6c2
5
5
  SHA512:
6
- metadata.gz: 53de6ccec73c0364e3e44d4cfed19dce8f9e18a2ad4a2410e9130a6a0bf49c1289b45e7feec982ff37fd64b4a34d9a496dd781c6838769c9e9a17fb69a1b1ae0
7
- data.tar.gz: 60a69e449ad623029f4114e412e6dd12394fd29e00650a910db106620bb414d92a3d3273faa74e7008e2c541d3fb759344aa4ee9b1fa5149c71f4c5ccd710566
6
+ metadata.gz: 2c40baa22b05b1c652d3fd3fb617a4d81c2d5349d6aa550dc49c1a7bbd3dfdd74b576151848dc6430e6ad01ff76705000892129b5990a432429dc3a60de4b3d4
7
+ data.tar.gz: 49900c83dd33dd65ccf0bf0221c130b6363a35d14eafa25403930d0990e445e94cb60d0344b0e0988485a2d4e0acdf165204a0930620b8e8dbf218486a81704a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
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
+
15
+ ## [0.2.10](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.9...rails_lens/v0.2.10) (2025-10-17)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * handle PostgreSQL schema-qualified table names in BestPracticesAnalyzer ([#24](https://github.com/seuros/rails_lens/issues/24)) ([607536f](https://github.com/seuros/rails_lens/commit/607536f58d8840a9123bc50eec7878b979cd1891))
21
+
3
22
  ## [0.2.9](https://github.com/seuros/rails_lens/compare/rails_lens/v0.2.8...rails_lens/v0.2.9) (2025-10-05)
4
23
 
5
24
 
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
@@ -65,7 +65,11 @@ module RailsLens
65
65
  end
66
66
 
67
67
  # Check table naming
68
- if !table_name.match?(/^[a-z_]+$/) || table_name != table_name.pluralize
68
+ # Extract the actual table name without schema prefix for PostgreSQL
69
+ # PostgreSQL uses schema.table format (e.g., "ai.skills" -> "skills")
70
+ unqualified_table = table_name.to_s.split('.').last
71
+
72
+ if !unqualified_table.match?(/^[a-z_]+$/) || unqualified_table != unqualified_table.pluralize
69
73
  notes << "Table name '#{table_name}' doesn't follow Rails conventions (should be plural, snake_case)"
70
74
  end
71
75
 
@@ -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
@@ -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
- module Configuration
5
- extend ActiveSupport::Concern
4
+ class Config
5
+ attr_accessor :verbose, :debug, :raise_on_error, :logger,
6
+ :annotations, :erd, :schema, :extensions, :routes, :mailers
6
7
 
7
- included do
8
- # Add configuration for error handling
9
- config_accessor :verbose, default: false
10
- config_accessor :debug, default: false
11
- config_accessor :raise_on_error, default: false
8
+ def initialize
9
+ @verbose = false
10
+ @debug = false
11
+ @raise_on_error = false
12
+ @logger = nil
12
13
 
13
- # Logger configuration
14
- config_accessor :logger
14
+ @annotations = {
15
+ position: :before,
16
+ format: :rdoc
17
+ }
15
18
 
16
- # Configuration using ActiveSupport::Configurable
17
- config_accessor :annotations do
18
- {
19
- position: :before,
20
- format: :rdoc
21
- }
22
- end
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
- config_accessor :erd do
25
- {
26
- output_dir: 'doc/erd',
27
- orientation: 'TB',
28
- theme: true,
29
- default_colors: %w[
30
- lightblue
31
- lightcoral
32
- lightgreen
33
- lightyellow
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
- end
45
+ }
40
46
 
41
- config_accessor :schema do
42
- {
43
- adapter: :auto,
44
- include_notes: true,
45
- exclude_tables: nil, # Will use ActiveRecord::SchemaDumper.ignore_tables if nil
46
- format_options: {
47
- show_defaults: true,
48
- show_comments: true,
49
- show_foreign_keys: true,
50
- show_indexes: true,
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
- config_accessor :extensions do
57
- {
58
- enabled: true,
59
- autoload: true,
60
- interface_version: '1.0',
61
- ignore: [],
62
- custom_paths: [],
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
- config_accessor :routes do
70
- {
71
- enabled: true,
72
- include_defaults: true,
73
- include_constraints: true,
74
- pattern: '**/*_controller.rb',
75
- exclusion_pattern: 'vendor/**/*_controller.rb'
76
- }
77
- end
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
- config_accessor :mailers do
80
- {
81
- enabled: true,
82
- include_templates: true,
83
- include_delivery_methods: true,
84
- include_variables: true,
85
- include_locales: true,
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsLens
4
- VERSION = '0.2.9'
4
+ VERSION = '0.2.11'
5
5
  end
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
- include ActiveSupport::Configurable
33
- include Configuration
31
+ extend Configuration
34
32
 
35
33
  class << self
36
34
  def logger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  requirements: []
266
- rubygems_version: 3.7.2
266
+ rubygems_version: 3.6.9
267
267
  specification_version: 4
268
268
  summary: Comprehensive Rails application visualization and annotation
269
269
  test_files: []