annotated 0.1.0 → 0.1.2

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: c85b0403da4d884cb9bcad2c582deea76061b27f6cc5698eb71412d6dcacf63e
4
- data.tar.gz: 4deb819b9a5c8c6a17a5c8acf93f33d3a2c6d10c5c536a18503b81fdfbb03669
3
+ metadata.gz: 322fcfe312ecabf47905840164d0a358f1b55ceb1e501f209dcd4dd005be7f2d
4
+ data.tar.gz: b8b68c701826e8675387644ce445afd7dd0b2ad7ee820a9753e54ccbc329cedc
5
5
  SHA512:
6
- metadata.gz: b1cd2a160906a20a2e3e5ff6d334424acd2dbcad7d22711995cd04981cc0395b1a4e463e2ddcfd1d0042dc21746462dee0bd4a0e6a94f3b113aabb574aae7c42
7
- data.tar.gz: 187a89fca82c468eece48c5302686fcb7ea10b387a0ac62e8981cca0be073aa66119eeff593a5db6f42e4f03d391a4b6db26a91aec5672d8fe53e7cd540b74f7
6
+ metadata.gz: 4f8a6bc14a6879e94988861ef372efbb839919c35677ab40e13e20f59b2b0f56516de3b189ab651100fa193c6fc1eb07cefa0f53c0c582e3df1ccf71acafa430
7
+ data.tar.gz: def9e9b25d63cf4dbbc4a1a50777c5dd30296bf9842e5f91452249d459eeb3603fc1f7134649d77df2f0af5523f317ff653f708fe4b79a9cce452fbc27df2dcf
data/README.md CHANGED
@@ -55,31 +55,6 @@ when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`:
55
55
 
56
56
  Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`.
57
57
 
58
-
59
- ## Upgrading to 3.X and annotate models not working?
60
-
61
- In versions 2.7.X the annotate gem defaulted to annotating models if no arguments were passed in.
62
- The annotate gem by default would not allow for routes and models to be annotated together.
63
- A [change was added in #647](https://github.com/ctran/annotate_models/pull/647).
64
- You [can read more here](https://github.com/ctran/annotate_models/issues/663).
65
-
66
- There are a few ways of fixing this:
67
-
68
- - If using CLI explicitly pass in models flag using `--models`
69
-
70
- OR
71
-
72
- a) Running `rails g annotate:install` will overwrite your defaults with the annotating `models` option set to `'true'`.
73
-
74
- b) In `lib/tasks/auto_annotate_models.rake` add the `models` key-value option:
75
-
76
- ```ruby
77
- Annotated.set_defaults(
78
- ...
79
- 'models' => 'true',
80
- ...
81
- ```
82
-
83
58
  ## Install
84
59
 
85
60
  Into Gemfile from rubygems.org:
@@ -90,12 +65,10 @@ group :development do
90
65
  end
91
66
  ```
92
67
 
93
- Into Gemfile from Github:
68
+ Or
94
69
 
95
70
  ```ruby
96
- group :development do
97
- gem 'annotated', git: 'https://github.com/thedumbtechguy/annotated.git'
98
- end
71
+ bundle add annotated --group=development
99
72
  ```
100
73
 
101
74
  Into environment gems from rubygems.org:
@@ -106,7 +79,7 @@ Into environment gems from rubygems.org:
106
79
 
107
80
  ## Usage
108
81
 
109
- (If you used the Gemfile install, prefix the below commands with `bundle exec`.)
82
+ (If you installed globally (`gem install`), you can drop the `bundle exec` prefix)
110
83
 
111
84
  ### Usage in Rails
112
85
 
@@ -5,5 +5,9 @@ module ::ActiveRecord
5
5
  def self.method_missing(_name, *_args)
6
6
  # ignore this, so unknown/unloaded macros won't cause parsing to fail
7
7
  end
8
+
9
+ def self.respond_to_missing?(_name, *_args)
10
+ true
11
+ end
8
12
  end
9
13
  end
@@ -43,10 +43,16 @@ module AnnotateModels
43
43
 
44
44
  class << self
45
45
  def annotate_pattern(options = {})
46
+ # The annotation body runs up to its closing bare "#" (or "#++" for rdoc) line,
47
+ # so comments placed directly below it (e.g. class docs) are left alone.
48
+ body = /(?:(?:#.*\R)*#(?:\+\+)?\R|(?:#.*\R)*)/
49
+ wrapper_close = options[:wrapper_close] ? /(?:# #{options[:wrapper_close]}.*\R)?/ : //
50
+ annotation = /\R?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\R#{body}#{wrapper_close}\R*/
51
+
46
52
  if options[:wrapper_open]
47
- return /(?:^(\n|\r\n)?# (?:#{options[:wrapper_open]}).*(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*)|^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/
53
+ return /(?:^\R?# (?:#{options[:wrapper_open]}).*#{annotation})|^#{annotation}/
48
54
  end
49
- /^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/o
55
+ /^#{annotation}/
50
56
  end
51
57
 
52
58
  def model_dir
@@ -145,7 +151,14 @@ module AnnotateModels
145
151
  bare_type_allowance = 16
146
152
 
147
153
  if options[:format_markdown]
148
- info << sprintf("# %-#{max_size + md_names_overhead}.#{max_size + md_names_overhead}s | %-#{md_type_allowance}.#{md_type_allowance}s | %s\n", "Name", "Type", "Attributes")
154
+ info << sprintf(
155
+ "# %-*.*s | %-*.*s | %s\n",
156
+ max_size + md_names_overhead, max_size + md_names_overhead,
157
+ "Name",
158
+ md_type_allowance, md_type_allowance,
159
+ "Type",
160
+ "Attributes"
161
+ )
149
162
 
150
163
  info << "# #{"-" * (max_size + md_names_overhead)} | #{"-" * md_type_allowance} | #{"-" * 27}\n"
151
164
  end
@@ -179,7 +192,12 @@ module AnnotateModels
179
192
  col_comment = cols_meta[col.name][:col_comment]
180
193
 
181
194
  if options[:format_rdoc]
182
- info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
195
+ info << sprintf(
196
+ "# %-*.*s<tt>%s</tt>",
197
+ max_size, max_size,
198
+ "*#{col_name}*::",
199
+ attrs.unshift(col_type).join(", ")
200
+ ).rstrip + "\n"
183
201
  elsif options[:format_yard]
184
202
  info << sprintf("# @!attribute #{col_name}") + "\n"
185
203
  ruby_class = (col.respond_to?(:array) && col.array) ? "Array<#{map_col_type_to_ruby_classes(col_type)}>" : map_col_type_to_ruby_classes(col_type)
@@ -187,7 +205,14 @@ module AnnotateModels
187
205
  elsif options[:format_markdown]
188
206
  name_remainder = max_size - col_name.length - non_ascii_length(col_name)
189
207
  type_remainder = (md_type_allowance - 2) - col_type.length
190
- info << sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip).gsub("``", " ").rstrip + "\n"
208
+ info << sprintf(
209
+ "# **`%s`**%*s | `%s`%*s | `%s`",
210
+ col_name,
211
+ name_remainder, " ",
212
+ col_type,
213
+ type_remainder, " ",
214
+ attrs.join(", ").rstrip
215
+ ).gsub("``", " ").rstrip + "\n"
191
216
  elsif with_comments_column
192
217
  info << format_default(col_name, max_size, col_type, bare_type_allowance, simple_formatted_attrs, bare_max_attrs_length, col_comment)
193
218
  else
@@ -314,7 +339,8 @@ module AnnotateModels
314
339
 
315
340
  def final_index_string(index, max_size)
316
341
  sprintf(
317
- "# %-#{max_size}.#{max_size}s %s%s%s%s",
342
+ "# %-*.*s %s%s%s%s",
343
+ max_size, max_size,
318
344
  index.name,
319
345
  "(#{index_columns_info(index).join(",")})",
320
346
  index_unique_info(index),
@@ -374,7 +400,7 @@ module AnnotateModels
374
400
  fk_info << if options[:format_markdown]
375
401
  sprintf("# * `%s`%s:\n# * **`%s`**\n", format_name.call(fk), constraints_info.blank? ? "" : " (_#{constraints_info}_)", ref_info)
376
402
  else
377
- sprintf("# %-#{max_size}.#{max_size}s %s %s", format_name.call(fk), "(#{ref_info})", constraints_info).rstrip + "\n"
403
+ sprintf("# %-*.*s %s %s", max_size, max_size, format_name.call(fk), "(#{ref_info})", constraints_info).rstrip + "\n"
378
404
  end
379
405
  end
380
406
 
@@ -403,7 +429,7 @@ module AnnotateModels
403
429
  cc_info_markdown << sprintf(": `%s`", expression) if expression
404
430
  cc_info_markdown << "\n"
405
431
  else
406
- sprintf("# %-#{max_size}.#{max_size}s %s", check_constraint.name, expression).rstrip + "\n"
432
+ sprintf("# %-*.*s %s", max_size, max_size, check_constraint.name, expression).rstrip + "\n"
407
433
  end
408
434
  end
409
435
 
@@ -434,8 +460,8 @@ module AnnotateModels
434
460
  new_header = info_block.match(header_pattern).to_s
435
461
 
436
462
  column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
437
- old_columns = old_header && old_header.scan(column_pattern).sort
438
- new_columns = new_header && new_header.scan(column_pattern).sort
463
+ old_columns = old_header&.scan(column_pattern)&.sort
464
+ new_columns = new_header&.scan(column_pattern)&.sort
439
465
 
440
466
  return false if old_columns == new_columns && !options[:force]
441
467
 
@@ -647,7 +673,7 @@ module AnnotateModels
647
673
  if File.file?(file_path) && Kernel.require(file_path)
648
674
  retry
649
675
  elsif /\//.match?(model_path)
650
- model_path = model_path.split("/")[1..-1].join("/").to_s
676
+ model_path = model_path.split("/")[1..].join("/").to_s
651
677
  retry
652
678
  else
653
679
  raise
@@ -869,7 +895,7 @@ module AnnotateModels
869
895
  end
870
896
 
871
897
  def non_ascii_length(string)
872
- string.to_s.chars.reject(&:ascii_only?).length
898
+ string.to_s.chars.count { |element| !element.ascii_only? }
873
899
  end
874
900
 
875
901
  def map_col_type_to_ruby_classes(col_type)
@@ -889,7 +915,7 @@ module AnnotateModels
889
915
  cols = klass.columns
890
916
  cols += translated_columns(klass)
891
917
 
892
- if ignore_columns = options[:ignore_columns]
918
+ if (ignore_columns = options[:ignore_columns])
893
919
  cols = cols.reject do |col|
894
920
  col.name.match(/#{ignore_columns}/)
895
921
  end
@@ -969,7 +995,7 @@ module AnnotateModels
969
995
  # If the index includes another column, print it too.
970
996
  if options[:simple_indexes] && klass.table_exists? # Check out if this column is indexed
971
997
  indices = retrieve_indexes_from_table(klass)
972
- if indices = indices.select { |ind| ind.columns.include? column.name }
998
+ if (indices = indices.select { |ind| ind.columns.include? column.name })
973
999
  indices.sort_by(&:name).each do |ind|
974
1000
  next if ind.columns.is_a?(String)
975
1001
  ind = ind.columns.reject! { |i| i == column.name }
@@ -57,7 +57,7 @@ module AnnotateRoutes
57
57
  out << comment
58
58
  return out if contents_without_magic_comments.size.zero?
59
59
 
60
- maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..-1].map { |line| line.split.map(&:size) }
60
+ maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..].map { |line| line.split.map(&:size) }
61
61
 
62
62
  if markdown?
63
63
  max = maxs.map(&:max).compact.max
@@ -68,7 +68,7 @@ module AnnotateRoutes
68
68
  out << comment(content(contents_without_magic_comments[0], maxs))
69
69
  end
70
70
 
71
- out += contents_without_magic_comments[1..-1].map { |line| comment(content(markdown? ? line.split(" ") : line, maxs)) }
71
+ out += contents_without_magic_comments[1..].map { |line| comment(content(markdown? ? line.split(" ") : line, maxs)) }
72
72
  out << comment(options[:wrapper_close]) if options[:wrapper_close]
73
73
 
74
74
  out
@@ -1,5 +1,5 @@
1
1
  module Annotated
2
2
  def self.version
3
- "0.1.0"
3
+ "0.1.2"
4
4
  end
5
5
  end
@@ -2,7 +2,8 @@
2
2
  # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
3
  # NOTE: to have a dev-mode tool do its thing in production.
4
4
  if Rails.env.development?
5
- require "annotate"
5
+ require "annotated"
6
+
6
7
  task :set_annotation_options do
7
8
  # You can override any of these by setting an environment variable of the
8
9
  # same name.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2025-01-11 00:00:00.000000000 Z
16
+ date: 2026-10-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.5.16
96
+ rubygems_version: 3.4.10
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Annotates Rails Models, routes, fixtures, and others based on the database