annotate 3.1.0 → 3.1.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: ff5fdb0f67e1790c14efff769d33ea5bd83e0120a2aa90ed3c738d04a8247266
4
- data.tar.gz: 07d173cb24fe0476aba4152feb618c29a303705e882301718177ed7ad34501e4
3
+ metadata.gz: 14932a4a189792b68c9d85c63313d0d60322ca22fed18a7a4a00edd47348743a
4
+ data.tar.gz: 351b61b7b3eac94f1ce6d8a86e1630bbbf6c0920cacfe46319163a86bc189887
5
5
  SHA512:
6
- metadata.gz: 8c2e1d4d012e7d65b1282bc8497db61d9d95bdfa1ea1709d362d3b1c35609d659183f58a42ae3e48833a6be9519daf09e2b538b06b7ccf1706d2c963c4301027
7
- data.tar.gz: 8ac9930d48f5ed72d1f6b453956882c637360323b31bc465d0ff3803f015c1adc93275c0a4eb46d29431588bc1b8110e8a5408f81d417e0b65d5132e318c25a4
6
+ metadata.gz: a717f48aff793ea4566fca6919eb4fe85b1545fe93b0bece91c5a9507cbb87fe14aa35ac520e618e98f8db92fe11010a8fe8653802b25b83b24590467e5d64f1
7
+ data.tar.gz: d13aab072e5e3901788f4aff809e08f3d28ac24cf0eed4187b0e5c0f98008f3c95a7553b58c4f50705f2f42729e96a05a57631356715953bb7d29531e4365fbd
@@ -1,3 +1,17 @@
1
+ ## 3.1.1
2
+ Changes
3
+ - Bump required ruby version to >= 2.4 [#772](https://github.com/ctran/annotate_models/pull/772)
4
+ - [Revert #677] Fix column default annotations [#768](https://github.com/ctran/annotate_models/pull/768)
5
+
6
+ Project Improvements
7
+ - Refactor by adding AnnotateRoutes::Helpers [#770](https://github.com/ctran/annotate_models/pull/770)
8
+ - Bump puma from 4.3.1 to 4.3.3 in /spec/integration/rails_6.0.2.1 [#771](https://github.com/ctran/annotate_models/pull/771)
9
+ - Bump puma from 3.12.2 to 4.3.3 in /spec/integration/rails_5.2.4.1 [#769](https://github.com/ctran/annotate_models/pull/769)
10
+ - Bump nokogiri from 1.10.7 to 1.10.8 in /spec/integration/rails_5.2.4.1 [#766](https://github.com/ctran/annotate_models/pull/766)
11
+ - Bump nokogiri from 1.10.7 to 1.10.8 in /spec/integration/rails_6.0.2.1 [#765](https://github.com/ctran/annotate_models/pull/765)
12
+ - Refactor test cases of AnnotateRoutes [#760](https://github.com/ctran/annotate_models/pull/760)
13
+ - Rename FactoryGirl -> FactoryBot comment [#759](https://github.com/ctran/annotate_models/pull/759)
14
+
1
15
  ## 3.1.0
2
16
  Changes
3
17
  - Fix new lines after comments for rubocop compatibility [#757](https://github.com/ctran/annotate_models/pull/757)
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.name = 'annotate'
8
8
  s.version = Annotate.version
9
9
 
10
- s.required_ruby_version = '>= 2.2.0'
10
+ s.required_ruby_version = '>= 2.4.0'
11
11
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ['Alex Chaffee', 'Cuong Tran', 'Marcos Piccinini', 'Turadg Aleahmad', 'Jon Frisby']
13
13
  s.description = 'Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.'
@@ -38,7 +38,7 @@ module AnnotateModels
38
38
  BLUEPRINTS_TEST_DIR = File.join('test', "blueprints")
39
39
  BLUEPRINTS_SPEC_DIR = File.join('spec', "blueprints")
40
40
 
41
- # Factory Girl https://github.com/thoughtbot/factory_bot
41
+ # Factory Bot https://github.com/thoughtbot/factory_bot
42
42
  FACTORY_BOT_TEST_DIR = File.join('test', "factories")
43
43
  FACTORY_BOT_SPEC_DIR = File.join('spec', "factories")
44
44
 
@@ -213,7 +213,7 @@ module AnnotateModels
213
213
  end
214
214
 
215
215
  def schema_default(klass, column)
216
- quote(klass.columns.find { |x| x.name.to_s == column.name.to_s }.try(:default))
216
+ quote(klass.column_defaults[column.name])
217
217
  end
218
218
 
219
219
  def retrieve_indexes_from_table(klass)
@@ -19,18 +19,19 @@
19
19
  #
20
20
  # Released under the same license as Ruby. No Support. No Warranty.
21
21
  #
22
+
23
+ require_relative './annotate_routes/helpers'
24
+
22
25
  module AnnotateRoutes
23
26
  PREFIX = '== Route Map'.freeze
24
27
  PREFIX_MD = '## Route Map'.freeze
25
28
  HEADER_ROW = ['Prefix', 'Verb', 'URI Pattern', 'Controller#Action'].freeze
26
29
 
27
- MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze
28
-
29
30
  class << self
30
31
  def do_annotations(options = {})
31
32
  if routes_file_exist?
32
33
  existing_text = File.read(routes_file)
33
- content, header_position = strip_annotations(existing_text)
34
+ content, header_position = Helpers.strip_annotations(existing_text)
34
35
  new_content = annotate_routes(header(options), content, header_position, options)
35
36
  new_text = new_content.join("\n")
36
37
 
@@ -47,7 +48,7 @@ module AnnotateRoutes
47
48
  def remove_annotations(_options={})
48
49
  if routes_file_exist?
49
50
  existing_text = File.read(routes_file)
50
- content, header_position = strip_annotations(existing_text)
51
+ content, header_position = Helpers.strip_annotations(existing_text)
51
52
  new_content = strip_on_removal(content, header_position)
52
53
  new_text = new_content.join("\n")
53
54
  if rewrite_contents(existing_text, new_text)
@@ -73,7 +74,7 @@ module AnnotateRoutes
73
74
  def header(options = {})
74
75
  routes_map = app_routes_map(options)
75
76
 
76
- magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map)
77
+ magic_comments_map, routes_map = Helpers.extract_magic_comments_from_array(routes_map)
77
78
 
78
79
  out = []
79
80
 
@@ -113,35 +114,6 @@ module AnnotateRoutes
113
114
  end
114
115
  end
115
116
 
116
- # TODO: write the method doc using ruby rdoc formats
117
- # This method returns an array of 'real_content' and 'header_position'.
118
- # 'header_position' will either be :before, :after, or
119
- # a number. If the number is > 0, the
120
- # annotation was found somewhere in the
121
- # middle of the file. If the number is
122
- # zero, no annotation was found.
123
- def strip_annotations(content)
124
- real_content = []
125
- mode = :content
126
- header_position = 0
127
-
128
- content.split(/\n/, -1).each_with_index do |line, line_number|
129
- if mode == :header && line !~ /\s*#/
130
- mode = :content
131
- real_content << line unless line.blank?
132
- elsif mode == :content
133
- if line =~ /^\s*#\s*== Route.*$/
134
- header_position = line_number + 1 # index start's at 0
135
- mode = :header
136
- else
137
- real_content << line
138
- end
139
- end
140
- end
141
-
142
- real_content_and_header_position(real_content, header_position)
143
- end
144
-
145
117
  def strip_on_removal(content, header_position)
146
118
  if header_position == :before
147
119
  content.shift while content.first == ''
@@ -168,7 +140,7 @@ module AnnotateRoutes
168
140
  end
169
141
 
170
142
  def annotate_routes(header, content, header_position, options = {})
171
- magic_comments_map, content = extract_magic_comments_from_array(content)
143
+ magic_comments_map, content = Helpers.extract_magic_comments_from_array(content)
172
144
  if %w(before top).include?(options[:position_in_routes])
173
145
  header = header << '' if content.first != ''
174
146
  magic_comments_map << '' if magic_comments_map.any?
@@ -208,24 +180,6 @@ module AnnotateRoutes
208
180
  routes_map
209
181
  end
210
182
 
211
- # @param [Array<String>] content
212
- # @return [Array<String>] all found magic comments
213
- # @return [Array<String>] content without magic comments
214
- def extract_magic_comments_from_array(content_array)
215
- magic_comments = []
216
- new_content = []
217
-
218
- content_array.each do |row|
219
- if row =~ MAGIC_COMMENT_MATCHER
220
- magic_comments << row.strip
221
- else
222
- new_content << row
223
- end
224
- end
225
-
226
- [magic_comments, new_content]
227
- end
228
-
229
183
  def content(line, maxs, options = {})
230
184
  return line.rstrip unless options[:format_markdown]
231
185
 
@@ -235,18 +189,5 @@ module AnnotateRoutes
235
189
  sprintf("%-#{min_length}.#{min_length}s", elem.tr('|', '-'))
236
190
  end.join(' | ')
237
191
  end
238
-
239
- def real_content_and_header_position(real_content, header_position)
240
- # By default assume the annotation was found in the middle of the file
241
-
242
- # ... unless we have evidence it was at the beginning ...
243
- return real_content, :before if header_position == 1
244
-
245
- # ... or that it was at the end.
246
- return real_content, :after if header_position >= real_content.count
247
-
248
- # and the default
249
- return real_content, header_position
250
- end
251
192
  end
252
193
  end
@@ -0,0 +1,69 @@
1
+ module AnnotateRoutes
2
+ module Helpers
3
+ MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze
4
+
5
+ class << self
6
+ # TODO: write the method doc using ruby rdoc formats
7
+ # This method returns an array of 'real_content' and 'header_position'.
8
+ # 'header_position' will either be :before, :after, or
9
+ # a number. If the number is > 0, the
10
+ # annotation was found somewhere in the
11
+ # middle of the file. If the number is
12
+ # zero, no annotation was found.
13
+ def strip_annotations(content)
14
+ real_content = []
15
+ mode = :content
16
+ header_position = 0
17
+
18
+ content.split(/\n/, -1).each_with_index do |line, line_number|
19
+ if mode == :header && line !~ /\s*#/
20
+ mode = :content
21
+ real_content << line unless line.blank?
22
+ elsif mode == :content
23
+ if line =~ /^\s*#\s*== Route.*$/
24
+ header_position = line_number + 1 # index start's at 0
25
+ mode = :header
26
+ else
27
+ real_content << line
28
+ end
29
+ end
30
+ end
31
+
32
+ real_content_and_header_position(real_content, header_position)
33
+ end
34
+
35
+ # @param [Array<String>] content
36
+ # @return [Array<String>] all found magic comments
37
+ # @return [Array<String>] content without magic comments
38
+ def extract_magic_comments_from_array(content_array)
39
+ magic_comments = []
40
+ new_content = []
41
+
42
+ content_array.each do |row|
43
+ if row =~ MAGIC_COMMENT_MATCHER
44
+ magic_comments << row.strip
45
+ else
46
+ new_content << row
47
+ end
48
+ end
49
+
50
+ [magic_comments, new_content]
51
+ end
52
+
53
+ private
54
+
55
+ def real_content_and_header_position(real_content, header_position)
56
+ # By default assume the annotation was found in the middle of the file
57
+
58
+ # ... unless we have evidence it was at the beginning ...
59
+ return real_content, :before if header_position == 1
60
+
61
+ # ... or that it was at the end.
62
+ return real_content, :after if header_position >= real_content.count
63
+
64
+ # and the default
65
+ return real_content, header_position
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,5 +1,5 @@
1
1
  module Annotate
2
2
  def self.version
3
- '3.1.0'
3
+ '3.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-02-20 00:00:00.000000000 Z
15
+ date: 2020-03-24 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -80,6 +80,7 @@ files:
80
80
  - lib/annotate/active_record_patch.rb
81
81
  - lib/annotate/annotate_models.rb
82
82
  - lib/annotate/annotate_routes.rb
83
+ - lib/annotate/annotate_routes/helpers.rb
83
84
  - lib/annotate/constants.rb
84
85
  - lib/annotate/helpers.rb
85
86
  - lib/annotate/parser.rb
@@ -105,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
106
  requirements:
106
107
  - - ">="
107
108
  - !ruby/object:Gem::Version
108
- version: 2.2.0
109
+ version: 2.4.0
109
110
  required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  requirements:
111
112
  - - ">="