annotaterb 4.3.1 → 4.4.0

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: 638be873328bb99a7c5b8196ee15749e0c40e36fc3660204ceec28af42678f09
4
- data.tar.gz: 0e88670fc1257d20e6282aaf4f510d8b2be29829983dce6c63bcfc4078deb996
3
+ metadata.gz: 349c4c734ded99ebac4d6ec075372fe814dff54e7edd7834a4b7c254aa046571
4
+ data.tar.gz: 715b408a71123bc45986f4aca53c1c34b0debb92b01dc770085a7ba5aac6ae45
5
5
  SHA512:
6
- metadata.gz: 2142be1d47c96ac81a3ab97cfbb6d852ea952be8a179785b5cf48eadf9eec3e9ceff3588353a2d3efa6efeed071589664776948b96eda8e1df5cd4dd7335d0c6
7
- data.tar.gz: e6cc12cc6d7110283ba23243cc27f355f594d71fc2f5ce5ee50f535f84bfb2e8e6a440546e86a4e2ffa1f300afd819321bb81968e7a235486605bd219c5284bb
6
+ metadata.gz: d843a40644a70550177193b9f1e559c541852384bf4e26f489a45d6ad486d8ddf6157d94abc9c98072acfad802e3144db40fe9ba1e6a3b00018d7865c92dc78a
7
+ data.tar.gz: e3706615de5bca13aa90353aec34bcc9a728400c139321d051edac045d4c2f24edc032129f666eb012da7b88587bd90bab979e40f77fb25c0568b39559a8302a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.3.1](https://github.com/drwl/annotaterb/tree/v4.3.1) (2023-06-15)
4
+
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.3.0...v4.3.1)
6
+
7
+ **Closed issues:**
8
+
9
+ - Column defaults change in migration [\#45](https://github.com/drwl/annotaterb/issues/45)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Bump version to v4.3.1 [\#46](https://github.com/drwl/annotaterb/pull/46) ([drwl](https://github.com/drwl))
14
+ - Prettify column defaults [\#44](https://github.com/drwl/annotaterb/pull/44) ([drwl](https://github.com/drwl))
15
+ - Generate changelog for v4.3.0 [\#42](https://github.com/drwl/annotaterb/pull/42) ([drwl](https://github.com/drwl))
16
+
3
17
  ## [v4.3.0](https://github.com/drwl/annotaterb/tree/v4.3.0) (2023-06-10)
4
18
 
5
19
  [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.2.0...v4.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.3.1
1
+ 4.4.0
@@ -12,14 +12,14 @@ module AnnotateRb
12
12
  MD_NAMES_OVERHEAD = 6
13
13
  MD_TYPE_ALLOWANCE = 18
14
14
 
15
- def initialize(klass, options = {})
15
+ def initialize(klass, options)
16
16
  @model = ModelWrapper.new(klass, options)
17
17
  @options = options
18
18
  @info = "" # TODO: Make array and build string that way
19
19
  end
20
20
 
21
21
  def build
22
- @info = "# #{header}\n"
22
+ @info = "#{header}\n"
23
23
  @info += schema_header_text
24
24
 
25
25
  max_size = @model.max_schema_info_width
@@ -51,6 +51,7 @@ module AnnotateRb
51
51
 
52
52
  def header
53
53
  header = @options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
54
+ header = "# #{header}"
54
55
  version = begin
55
56
  ActiveRecord::Migrator.current_version
56
57
  rescue
@@ -69,11 +70,11 @@ module AnnotateRb
69
70
  info << "#"
70
71
 
71
72
  if @options[:format_markdown]
72
- info << "# Table name: `#{@model.table_name}`"
73
+ info << "# Table name: `#{table_name}`"
73
74
  info << "#"
74
75
  info << "# ### Columns"
75
76
  else
76
- info << "# Table name: #{@model.table_name}"
77
+ info << "# Table name: #{table_name}"
77
78
  end
78
79
  info << "#\n" # We want the last line break
79
80
 
@@ -93,6 +94,20 @@ module AnnotateRb
93
94
 
94
95
  info.join("\n")
95
96
  end
97
+
98
+ private
99
+
100
+ def table_name
101
+ table_name = @model.table_name
102
+ display_table_comments = @options[:with_comment] && @options[:with_table_comments]
103
+
104
+ if display_table_comments && @model.has_table_comments?
105
+ table_comment = "(#{@model.table_comments.gsub(/\n/, "\\n")})"
106
+ table_name = "#{table_name}#{table_comment}"
107
+ end
108
+
109
+ table_name
110
+ end
96
111
  end
97
112
  end
98
113
  end
@@ -26,7 +26,8 @@ module AnnotateRb
26
26
  column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices, column_defaults).build
27
27
  formatted_column_type = TypeBuilder.new(@column, @options, column_defaults).build
28
28
 
29
- col_name = if @model.with_comments? && @column.comment
29
+ display_column_comments = @options[:with_comment] && @options[:with_column_comments]
30
+ col_name = if display_column_comments && @model.with_comments? && @column.comment
30
31
  "#{@column.name}(#{@column.comment.gsub(/\n/, '\\n')})"
31
32
  else
32
33
  @column.name
@@ -4,13 +4,12 @@ module AnnotateRb
4
4
  module ModelAnnotator
5
5
  # Generates the text file content with annotations, these are then to be written to filesystem.
6
6
  class FileBuilder
7
- def initialize(file_components, new_annotations, annotation_position, options)
7
+ def initialize(file_components, annotation_position, options)
8
8
  @file_components = file_components
9
- @new_annotations = new_annotations
10
9
  @annotation_position = annotation_position
11
10
  @options = options
12
11
 
13
- @new_wrapped_annotations = wrapped_content(new_annotations)
12
+ @new_wrapped_annotations = wrapped_content(@file_components.new_annotations)
14
13
  end
15
14
 
16
15
  def generate_content_with_new_annotations
@@ -6,11 +6,14 @@ module AnnotateRb
6
6
  SKIP_ANNOTATION_STRING = "# -*- SkipSchemaAnnotations"
7
7
  SOME_PATTERN = /\A(?<start>\s*).*?\n(?<end>\s*)\z/m # Unsure what this pattern is
8
8
 
9
+ attr_reader :new_annotations
10
+
9
11
  def initialize(file_content, new_annotations, options)
10
12
  @file_content = file_content
11
13
  @diff = AnnotationDiffGenerator.new(file_content, new_annotations).generate
12
14
  @options = options
13
15
  @annotation_pattern = AnnotationPatternGenerator.call(options)
16
+ @new_annotations = new_annotations
14
17
  end
15
18
 
16
19
  def current_file_content
@@ -49,6 +49,15 @@ module AnnotateRb
49
49
  @klass.table_exists?
50
50
  end
51
51
 
52
+ def table_comments
53
+ @klass.connection.table_comment(@klass.table_name)
54
+ end
55
+
56
+ def has_table_comments?
57
+ @klass.connection.respond_to?(:table_comment) &&
58
+ @klass.connection.table_comment(@klass.table_name).present?
59
+ end
60
+
52
61
  def column_defaults
53
62
  @klass.column_defaults
54
63
  end
@@ -110,8 +119,7 @@ module AnnotateRb
110
119
  end
111
120
 
112
121
  def with_comments?
113
- @with_comments ||= @options[:with_comment] &&
114
- raw_columns.first.respond_to?(:comment) &&
122
+ @with_comments ||= raw_columns.first.respond_to?(:comment) &&
115
123
  raw_columns.map(&:comment).any? { |comment| !comment.nil? }
116
124
  end
117
125
 
@@ -26,7 +26,7 @@ module AnnotateRb
26
26
  old_content = File.read(file_name)
27
27
 
28
28
  file_components = FileComponents.new(old_content, annotation, options)
29
- builder = FileBuilder.new(file_components, annotation, annotation_position, options)
29
+ builder = FileBuilder.new(file_components, annotation_position, options)
30
30
 
31
31
  return false if file_components.has_skip_string?
32
32
  return false if !file_components.annotations_changed? && !options[:force]
@@ -51,7 +51,9 @@ module AnnotateRb
51
51
  sort: false, # ModelAnnotator
52
52
  timestamp: false, # RouteAnnotator
53
53
  trace: false, # ModelAnnotator, but is part of Core
54
- with_comment: true # ModelAnnotator
54
+ with_comment: true, # ModelAnnotator
55
+ with_column_comments: nil, # ModelAnnotator
56
+ with_table_comments: nil # ModelAnnotator
55
57
  }.freeze
56
58
 
57
59
  OTHER_OPTIONS = {
@@ -113,7 +115,9 @@ module AnnotateRb
113
115
  :sort,
114
116
  :timestamp,
115
117
  :trace,
116
- :with_comment
118
+ :with_comment,
119
+ :with_column_comments,
120
+ :with_table_comments
117
121
  ].freeze
118
122
 
119
123
  OTHER_OPTION_KEYS = [
@@ -187,6 +191,10 @@ module AnnotateRb
187
191
  @options[:wrapper_open] ||= @options[:wrapper]
188
192
  @options[:wrapper_close] ||= @options[:wrapper]
189
193
 
194
+ # Set column and table comments to default to :with_comment, if not set
195
+ @options[:with_column_comments] = @options[:with_comment] if @options[:with_column_comments].nil?
196
+ @options[:with_table_comments] = @options[:with_comment] if @options[:with_table_comments].nil?
197
+
190
198
  self
191
199
  end
192
200
 
@@ -217,6 +217,31 @@ module AnnotateRb
217
217
  "include database comments in model annotations") do
218
218
  @options[:with_comment] = true
219
219
  end
220
+
221
+ option_parser.on("--without-comment",
222
+ "include database comments in model annotations") do
223
+ @options[:with_comment] = false
224
+ end
225
+
226
+ option_parser.on("--with-column-comments",
227
+ "include column comments in model annotations") do
228
+ @options[:with_column_comments] = true
229
+ end
230
+
231
+ option_parser.on("--without-column-comments",
232
+ "exclude column comments in model annotations") do
233
+ @options[:with_column_comments] = false
234
+ end
235
+
236
+ option_parser.on("--with-table-comments",
237
+ "include table comments in model annotations") do
238
+ @options[:with_table_comments] = true
239
+ end
240
+
241
+ option_parser.on("--without-table-comments",
242
+ "exclude table comments in model annotations") do
243
+ @options[:with_table_comments] = false
244
+ end
220
245
  end
221
246
 
222
247
  def add_route_options_to_parser(option_parser)
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.3.1
4
+ version: 4.4.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: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2023-06-24 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.