annotaterb 4.7.0 → 4.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31e6cf08a5d57a35274e5964a5da9e4a01d006e0ddf3d4ac4467932901709ac
4
- data.tar.gz: 020ad6bab20eb3c029173d5764050d7c62855785c2fa357750bc2fbff27cd02b
3
+ metadata.gz: e7b61329d5886c3d24def7469ff273e6692c08a5f8f2340a7f6471f993190e17
4
+ data.tar.gz: 8fcb5a79d2be122867131b8a3779318958326564f6c3c36e4c53e4e0ee7b4250
5
5
  SHA512:
6
- metadata.gz: 1a52c81202a634161721175021e8ee8742cad49f0eab0aab2e89319d856a8f81fe0e1e2ea3de1e78e3695f261a6d2ee5bd5b41ea1ac8c9b2d072a62bcec4b1cd
7
- data.tar.gz: b01f86669748d083e52a0f3fef891632cff7fcf1c476ae1ce71e5e654cc028105435c4ceadcc73b23443dba28f3dd9c082ebbadeae541ad053a3cd93005d59cb
6
+ metadata.gz: 2c9fe857ae8f3627ff4fe42a419c6123cf9697419d766798abc81b3cf40c6cfb23ad6978d9daab4db7e6888fdfbf9574f4562a9949ab5344b7d3f6df168aff80
7
+ data.tar.gz: 3cf70f50b4c9ef6f97b08ab91dc7b538806dce0be9a1b4b45be68d132afa74828b306e63544f1be18739a7a85149f4af19f033feeb5899ae575ef61726be27d5
data/CHANGELOG.md CHANGED
@@ -1,13 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.7.0](https://github.com/drwl/annotaterb/tree/v4.7.0) (2024-03-27)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.6.0...v4.7.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - Feature request: better custom type representation [\#97](https://github.com/drwl/annotaterb/issues/97)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Bump version to v4.7.0 [\#100](https://github.com/drwl/annotaterb/pull/100) ([drwl](https://github.com/drwl))
14
+ - Add configurable classes list with `to_s` representation [\#98](https://github.com/drwl/annotaterb/pull/98) ([viralpraxis](https://github.com/viralpraxis))
15
+ - Generate changelog for v4.6.0 [\#96](https://github.com/drwl/annotaterb/pull/96) ([drwl](https://github.com/drwl))
16
+
3
17
  ## [v4.6.0](https://github.com/drwl/annotaterb/tree/v4.6.0) (2024-02-27)
4
18
 
5
19
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.5.0...v4.6.0)
6
20
 
7
- Adds two big changes: Fix annotations swallowing comments [\#72](https://github.com/drwl/annotaterb/pull/72) and
8
- Add Zeitwerk support [\#85](https://github.com/drwl/annotaterb/pull/85).
9
- Please report any issues you encounter.
10
-
11
21
  **Closed issues:**
12
22
 
13
23
  - Add support for `data_migrate` gem [\#89](https://github.com/drwl/annotaterb/issues/89)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.7.0
1
+ 4.7.1
@@ -44,6 +44,10 @@ module AnnotateRb
44
44
  @info += ForeignKeyAnnotation::AnnotationBuilder.new(@model, @options).build
45
45
  end
46
46
 
47
+ if @options[:show_check_constraints] && @model.table_exists?
48
+ @info += CheckConstraintAnnotation::AnnotationBuilder.new(@model, @options).build
49
+ end
50
+
47
51
  @info += schema_footer_text
48
52
 
49
53
  @info
@@ -52,12 +56,19 @@ module AnnotateRb
52
56
  def header
53
57
  header = @options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
54
58
  header = "# #{header}"
55
- version = begin
56
- ActiveRecord::Migrator.current_version
57
- rescue
58
- 0
59
+
60
+ if @options.get_state(:current_version).nil?
61
+ migration_version = begin
62
+ ActiveRecord::Migrator.current_version
63
+ rescue
64
+ 0
65
+ end
66
+
67
+ @options.set_state(:current_version, migration_version)
59
68
  end
60
69
 
70
+ version = @options.get_state(:current_version)
71
+
61
72
  if @options[:include_version] && version > 0
62
73
  header += "\n# Schema version: #{version}"
63
74
  end
@@ -18,6 +18,10 @@ module AnnotateRb
18
18
  klass = ModelClassGetter.call(@file, @options)
19
19
 
20
20
  klass_is_a_class = klass.is_a?(Class)
21
+ # Methods such as #superclass only exist on a class. Because of how the code is structured, `klass` could be a
22
+ # module that does not support the #superclass method, so we want to return early.
23
+ return false if !klass_is_a_class
24
+
21
25
  klass_inherits_active_record_base = klass < ActiveRecord::Base
22
26
  klass_is_not_abstract = klass.respond_to?(:abstract_class) && !klass.abstract_class?
23
27
  klass_table_exists = klass.respond_to?(:abstract_class) && klass.table_exists?
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnnotateRb
4
+ module ModelAnnotator
5
+ module CheckConstraintAnnotation
6
+ class AnnotationBuilder
7
+ def initialize(model, options)
8
+ @model = model
9
+ @options = options
10
+ end
11
+
12
+ def build
13
+ constraint_info = if @options[:format_markdown]
14
+ "#\n# ### Check Constraints\n#\n"
15
+ else
16
+ "#\n# Check Constraints\n#\n"
17
+ end
18
+
19
+ return "" unless @model.connection.respond_to?(:supports_check_constraints?) &&
20
+ @model.connection.supports_check_constraints? && @model.connection.respond_to?(:check_constraints)
21
+
22
+ check_constraints = @model.connection.check_constraints(@model.table_name)
23
+ return "" if check_constraints.empty?
24
+
25
+ max_size = check_constraints.map { |check_constraint| check_constraint.name.size }.max + 1
26
+ check_constraints.sort_by(&:name).each do |check_constraint|
27
+ expression = check_constraint.expression ? "(#{check_constraint.expression.squish})" : nil
28
+
29
+ constraint_info += if @options[:format_markdown]
30
+ cc_info_in_markdown(check_constraint.name, expression)
31
+ else
32
+ cc_info_string(check_constraint.name, expression, max_size)
33
+ end
34
+ end
35
+
36
+ constraint_info
37
+ end
38
+
39
+ private
40
+
41
+ def cc_info_in_markdown(name, expression)
42
+ cc_info_markdown = sprintf("# * `%s`", name)
43
+ cc_info_markdown += sprintf(": `%s`", expression) if expression
44
+ cc_info_markdown += "\n"
45
+
46
+ cc_info_markdown
47
+ end
48
+
49
+ def cc_info_string(name, expression, max_size)
50
+ # standard:disable Lint/FormatParameterMismatch
51
+ sprintf("# %-#{max_size}.#{max_size}s %s", name, expression).rstrip + "\n"
52
+ # standard:enable Lint/FormatParameterMismatch
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnnotateRb
4
+ module ModelAnnotator
5
+ module CheckConstraintAnnotation
6
+ autoload :AnnotationBuilder, "annotate_rb/model_annotator/check_constraint_annotation/annotation_builder"
7
+ end
8
+ end
9
+ end
@@ -26,5 +26,6 @@ module AnnotateRb
26
26
  autoload :AnnotatedFile, "annotate_rb/model_annotator/annotated_file"
27
27
  autoload :FileParser, "annotate_rb/model_annotator/file_parser"
28
28
  autoload :ZeitwerkClassGetter, "annotate_rb/model_annotator/zeitwerk_class_getter"
29
+ autoload :CheckConstraintAnnotation, "annotate_rb/model_annotator/check_constraint_annotation"
29
30
  end
30
31
  end
@@ -45,6 +45,7 @@ module AnnotateRb
45
45
  ignore_unknown_models: false, # ModelAnnotator
46
46
  include_version: false, # ModelAnnotator
47
47
  show_complete_foreign_keys: false, # ModelAnnotator
48
+ show_check_constraints: false, # ModelAnnotator
48
49
  show_foreign_keys: true, # ModelAnnotator
49
50
  show_indexes: true, # ModelAnnotator
50
51
  simple_indexes: false, # ModelAnnotator
@@ -109,6 +110,7 @@ module AnnotateRb
109
110
  :ignore_model_sub_dir,
110
111
  :ignore_unknown_models,
111
112
  :include_version,
113
+ :show_check_constraints,
112
114
  :show_complete_foreign_keys,
113
115
  :show_foreign_keys,
114
116
  :show_indexes,
@@ -198,6 +198,12 @@ module AnnotateRb
198
198
  @options[:simple_indexes] = true
199
199
  end
200
200
 
201
+ option_parser.on("-c",
202
+ "--show-check-constraints",
203
+ "List the table's check constraints in the annotation") do
204
+ @options[:show_check_constraints] = true
205
+ end
206
+
201
207
  option_parser.on("--hide-limit-column-types VALUES",
202
208
  "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
203
209
  @options[:hide_limit_column_types] = values.to_s
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.7.0
4
+ version: 4.7.1
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: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-05-09 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.
@@ -46,6 +46,8 @@ files:
46
46
  - lib/annotate_rb/model_annotator/annotation_diff_generator.rb
47
47
  - lib/annotate_rb/model_annotator/annotator.rb
48
48
  - lib/annotate_rb/model_annotator/bad_model_file_error.rb
49
+ - lib/annotate_rb/model_annotator/check_constraint_annotation.rb
50
+ - lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb
49
51
  - lib/annotate_rb/model_annotator/column_annotation.rb
50
52
  - lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb
51
53
  - lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb