annotaterb 4.14.0 → 4.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 915a9aee6e9396080e4b115bc34466f422cc866aa31f64e8563a409f4ed53753
4
- data.tar.gz: 30e4511ae77313d4d1f7348599286815a85e56f2c100f31ca73cc7a1feaa59d4
3
+ metadata.gz: a31463c338bd23299c7249e3c444d8c1b630157bf9905cfeb203dfafb1a4d16a
4
+ data.tar.gz: ad12fccdeeb0186d6627ba237c417c637b1b6136f354313e81f09de90cef4665
5
5
  SHA512:
6
- metadata.gz: 8e1c00298956404ba517a54b803f0cae4235da530a1f2dfe6db35e58c3747ba4bc7304759375ecf51237870f2e4701b965192b235e1c430b08bd4d0340bf6dc1
7
- data.tar.gz: 63f51a4bbc1ebf2455aeeb8b3a7459a87787b309f5deae0a0e91df971bc28a36f77fa71f7b80a4fbe8f32d3660936fa41576f56569e72526fc2505a77c8fc6df
6
+ metadata.gz: af6ec6a16d36b65b00eb28f4736c46682aa0d47da4869503eaecb8a58a8ff34f783ac3986c09200f125279666a8b30658af1ba91a9ad5829d789846c1c9e82dd
7
+ data.tar.gz: ad7fbd08360072a24c2fbea2808c180806ae89da5775689d1f7cc2824fead770b771ac41667056e68da0921ae13948a6f3da48883ab2f0328506cbf7158a63c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.14.0](https://github.com/drwl/annotaterb/tree/v4.14.0) (2025-02-17)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.13.0...v4.14.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - How do I annotate models but NOT routes? [\#178](https://github.com/drwl/annotaterb/issues/178)
10
+ - Model Annotation Not Updated When Modifying Table Columns Using change\_table. [\#169](https://github.com/drwl/annotaterb/issues/169)
11
+ - annotate\_rb:install failing on Rails 8 [\#168](https://github.com/drwl/annotaterb/issues/168)
12
+ - Annotations with enums changing between db:create db:migrate and then db:migrate [\#167](https://github.com/drwl/annotaterb/issues/167)
13
+ - JSON parse error [\#155](https://github.com/drwl/annotaterb/issues/155)
14
+ - Feature: Add Support for dynamic fixtures with ERB [\#149](https://github.com/drwl/annotaterb/issues/149)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - Bump version to v4.14.0 [\#190](https://github.com/drwl/annotaterb/pull/190) ([drwl](https://github.com/drwl))
19
+ - Add expected file to automatically require [\#185](https://github.com/drwl/annotaterb/pull/185) ([drwl](https://github.com/drwl))
20
+ - Fix translation foreign key exclusion bug [\#181](https://github.com/drwl/annotaterb/pull/181) ([galori](https://github.com/galori))
21
+ - Lock `concurrent-ruby` gem to fix CI [\#180](https://github.com/drwl/annotaterb/pull/180) ([tagliala](https://github.com/tagliala))
22
+ - Chore: alert when multiple conmmands were selected [\#179](https://github.com/drwl/annotaterb/pull/179) ([OdenTakashi](https://github.com/OdenTakashi))
23
+ - Updated COLUMN\_PATTERN to handle optional metadata \(e.g., constraints or descriptions\) enclosed in parentheses. [\#170](https://github.com/drwl/annotaterb/pull/170) ([hatsu38](https://github.com/hatsu38))
24
+ - Opt-in for MFA requirement [\#166](https://github.com/drwl/annotaterb/pull/166) ([tagliala](https://github.com/tagliala))
25
+ - Fix typos [\#165](https://github.com/drwl/annotaterb/pull/165) ([tagliala](https://github.com/tagliala))
26
+ - Add support for virtual columns [\#163](https://github.com/drwl/annotaterb/pull/163) ([robbevp](https://github.com/robbevp))
27
+ - Generate changelog for v4.13.0 [\#160](https://github.com/drwl/annotaterb/pull/160) ([drwl](https://github.com/drwl))
28
+
3
29
  ## [v4.13.0](https://github.com/drwl/annotaterb/tree/v4.13.0) (2024-10-21)
4
30
 
5
31
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.12.0...v4.13.0)
@@ -293,7 +319,7 @@
293
319
  - Fix the default behavior for model annotator [\#20](https://github.com/drwl/annotaterb/pull/20) ([drwl](https://github.com/drwl))
294
320
  - Refactor model annotator [\#19](https://github.com/drwl/annotaterb/pull/19) ([drwl](https://github.com/drwl))
295
321
  - Removed unused helper methods and `Env` class [\#18](https://github.com/drwl/annotaterb/pull/18) ([drwl](https://github.com/drwl))
296
- - Update dummy app depdencies [\#17](https://github.com/drwl/annotaterb/pull/17) ([drwl](https://github.com/drwl))
322
+ - Update dummy app dependencies [\#17](https://github.com/drwl/annotaterb/pull/17) ([drwl](https://github.com/drwl))
297
323
 
298
324
  ## [v4.0.0](https://github.com/drwl/annotaterb/tree/v4.0.0) (2023-05-03)
299
325
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.14.0
1
+ 4.15.0
@@ -15,10 +15,9 @@ module AnnotateRb
15
15
  klass.eager_load!
16
16
  end
17
17
  else
18
- options[:model_dir].each do |dir|
19
- ::Rake::FileList["#{dir}/**/*.rb"].each do |fname|
20
- require File.expand_path(fname)
21
- end
18
+ model_files = ModelAnnotator::ModelFilesGetter.call(options)
19
+ model_files&.each do |model_file|
20
+ require model_file
22
21
  end
23
22
  end
24
23
  end
@@ -70,10 +70,16 @@ module AnnotateRb
70
70
  sorted_column_indices&.each do |index|
71
71
  indexed_columns = index.columns.reject { |i| i == @column.name }
72
72
 
73
- attrs << if indexed_columns.empty?
73
+ index_text = if index.unique
74
+ "uniquely indexed"
75
+ else
74
76
  "indexed"
77
+ end
78
+
79
+ attrs << if indexed_columns.empty?
80
+ index_text
75
81
  else
76
- "indexed => [#{indexed_columns.join(", ")}]"
82
+ "#{index_text} => [#{indexed_columns.join(", ")}]"
77
83
  end
78
84
  end
79
85
  end
@@ -13,7 +13,8 @@ module AnnotateRb
13
13
 
14
14
  return model_files if model_files.any?
15
15
 
16
- options[:model_dir].each do |dir|
16
+ model_dirs = options[:model_dir].flat_map { |model_dir| Dir[model_dir] }
17
+ model_dirs.each do |dir|
17
18
  Dir.chdir(dir) do
18
19
  list = if options[:ignore_model_sub_dir]
19
20
  Dir["*.rb"].map { |f| [dir, f] }
@@ -26,12 +27,14 @@ module AnnotateRb
26
27
  end
27
28
  end
28
29
 
29
- model_files
30
- rescue SystemCallError
31
- warn "No models found in directory '#{options[:model_dir].join("', '")}'."
32
- warn "Either specify models on the command line, or use the --model-dir option."
33
- warn "Call 'annotaterb --help' for more info."
34
- # exit 1 # TODO: Return exit code back to caller. Right now it messes up RSpec being able to run
30
+ if model_files.empty?
31
+ warn "No models found in directory '#{options[:model_dir].join("', '")}'."
32
+ warn "Either specify models on the command line, or use the --model-dir option."
33
+ warn "Call 'annotaterb --help' for more info."
34
+ # exit 1 # TODO: Return exit code back to caller. Right now it messes up RSpec being able to run
35
+ else
36
+ model_files
37
+ end
35
38
  end
36
39
 
37
40
  private
@@ -6,6 +6,8 @@ module AnnotateRb
6
6
  # Should be the wrapper for an ActiveRecord model that serves as the source of truth of the model
7
7
  # of the model that we're annotating
8
8
 
9
+ DEFAULT_TIMESTAMP_COLUMNS = %w[created_at updated_at]
10
+
9
11
  def initialize(klass, options)
10
12
  @klass = klass
11
13
  @options = options
@@ -107,6 +109,10 @@ module AnnotateRb
107
109
  end
108
110
 
109
111
  def retrieve_indexes_from_table
112
+ @indexes_from_table ||= _retrieve_indexes_from_table
113
+ end
114
+
115
+ def _retrieve_indexes_from_table
110
116
  table_name = @klass.table_name
111
117
  return [] unless table_name
112
118
 
@@ -114,7 +120,7 @@ module AnnotateRb
114
120
  return indexes if indexes.any? || !@klass.table_name_prefix
115
121
 
116
122
  # Try to search the table without prefix
117
- table_name_without_prefix = table_name.to_s.sub(@klass.table_name_prefix, "")
123
+ table_name_without_prefix = table_name.to_s.sub(@klass.table_name_prefix.to_s, "")
118
124
  begin
119
125
  @klass.connection.indexes(table_name_without_prefix)
120
126
  rescue ActiveRecord::StatementInvalid => _e
@@ -143,10 +149,13 @@ module AnnotateRb
143
149
  associations = []
144
150
  id = nil
145
151
 
152
+ # specs don't load defaults, so ensure we have defaults here
153
+ timestamp_columns = @options[:timestamp_columns] || DEFAULT_TIMESTAMP_COLUMNS
154
+
146
155
  cols.each do |c|
147
156
  if c.name.eql?("id")
148
157
  id = c
149
- elsif c.name.eql?("created_at") || c.name.eql?("updated_at")
158
+ elsif timestamp_columns.include?(c.name)
150
159
  timestamps << c
151
160
  elsif c.name[-3, 3].eql?("_id")
152
161
  associations << c
@@ -154,7 +163,10 @@ module AnnotateRb
154
163
  rest_cols << c
155
164
  end
156
165
  end
157
- [rest_cols, timestamps, associations].each { |a| a.sort_by!(&:name) }
166
+
167
+ timestamp_order = timestamp_columns.each_with_index.to_h
168
+ timestamps.sort_by! { |col| timestamp_order[col.name] }
169
+ [rest_cols, associations].each { |a| a.sort_by!(&:name) }
158
170
 
159
171
  ([id] << rest_cols << timestamps << associations).flatten.compact
160
172
  end
@@ -64,7 +64,10 @@ module AnnotateRb
64
64
  def get
65
65
  current_patterns = []
66
66
 
67
- @options[:root_dir].each do |root_directory|
67
+ root_dirs = @options[:root_dir].flat_map do |root_dir|
68
+ root_dir.empty? ? root_dir : Dir[root_dir]
69
+ end
70
+ root_dirs.each do |root_directory|
68
71
  Array(@pattern_types).each do |pattern_type|
69
72
  patterns = generate(root_directory, pattern_type)
70
73
 
@@ -34,6 +34,7 @@ module AnnotateRb
34
34
  private
35
35
 
36
36
  def build_instructions_for_file(file)
37
+ start = Time.now
37
38
  klass = ModelClassGetter.call(file, @options)
38
39
 
39
40
  instructions = []
@@ -52,6 +53,10 @@ module AnnotateRb
52
53
  end
53
54
  instructions.concat(related_file_instructions)
54
55
 
56
+ if @options[:debug]
57
+ puts "Built instructions for #{file} in #{Time.now - start}s"
58
+ end
59
+
55
60
  instructions
56
61
  end
57
62
 
@@ -69,6 +69,9 @@ module AnnotateRb
69
69
  # ModelAnnotator
70
70
  hide_limit_column_types: "",
71
71
 
72
+ # ModelAnnotator
73
+ timestamp_columns: ModelAnnotator::ModelWrapper::DEFAULT_TIMESTAMP_COLUMNS,
74
+
72
75
  ignore_columns: nil, # ModelAnnotator
73
76
  ignore_routes: nil, # RouteAnnotator
74
77
  ignore_unknown_models: false, # ModelAnnotator
@@ -130,6 +133,7 @@ module AnnotateRb
130
133
  :debug,
131
134
  :hide_default_column_types,
132
135
  :hide_limit_column_types,
136
+ :timestamp_columns,
133
137
  :ignore_columns,
134
138
  :ignore_routes,
135
139
  :ignore_unknown_models,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.14.0
4
+ version: 4.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew W. Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-17 00:00:00.000000000 Z
11
+ date: 2025-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
14
14
  on the database schema.
@@ -120,7 +120,7 @@ licenses:
120
120
  metadata:
121
121
  homepage_uri: https://github.com/drwl/annotaterb
122
122
  source_code_uri: https://github.com/drwl/annotaterb
123
- changelog_uri: https://github.com/drwl/annotaterb/blob/master/CHANGELOG.md
123
+ changelog_uri: https://github.com/drwl/annotaterb/blob/main/CHANGELOG.md
124
124
  bug_tracker_uri: https://github.com/drwl/annotaterb/issues
125
125
  rubygems_mfa_required: 'true'
126
126
  post_install_message: