annotate 3.0.0 → 3.0.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: 0e4ee3c38fb2ebf3d88712e8836f00570e891cd1a43a6c2bc32c95dc35b7a0d2
4
- data.tar.gz: 1082be239480425543d84491e8c03d54ad99b362cc142b93224517499d4417fa
3
+ metadata.gz: 1ed01c42404ffa9b87f256ce671d68a47065b6dc6880bf2e351a2ca94bc01e24
4
+ data.tar.gz: 62fa4fa3174f2a32b3d045d50ab3be26ff4647053c3e455f2fce70e8d4f8e24e
5
5
  SHA512:
6
- metadata.gz: 4896d07fc9b6d6b95d5916e566cc0d9a304cd16c1592ac0a0546bb273d533c7dfb275c55b2833586e677027e7f34f6a4f38281053e6e454553be527f4e23055c
7
- data.tar.gz: c72e8ba788014600e40ba24fe7385b9c6c10c08d293ee98bd71e0d91cc235c1a14242293ae963c9265c8e318fa09a104e60547a24c7697218b06be68f320fa63
6
+ metadata.gz: ec228f10fb750acdc34f8708385daa5943e0cda4ebe1f59633d67c29b906ff70e13880c800b5e8778d242007cec75e123e67969cdc61e6a2c84af9c2122d1613
7
+ data.tar.gz: 492a844a0e1be69e77a689c79e3b5896d187813b02be71c0a16d8666dedc29aabae91387f0c0031b103338dbaae0ee4dac3cf2d13e7aecee3ba1bfae865b9fd6
@@ -1,3 +1,11 @@
1
+ == 3.0.2
2
+ * Fixes `LoadError` due to gemspec not referencing `parser.rb`, issue #657 (#660)
3
+ * Changes `--additional_file_patterns` to use dashes `--additional-file-patterns` for consistency (#649)
4
+ * Refactor: moving constants into `constants.rb` (#653)
5
+
6
+ == 3.0.1
7
+ * Skipped as an official release, used the 3.0.1 patch for setting up Github Actions (#619)
8
+
1
9
  == 3.0.0
2
10
  * Added `--models` CLI option fixing issue #563 (#647)
3
11
  * Added `--additional_file_patterns` option for additional file patterns (#633) #636) #637)
@@ -163,7 +163,7 @@ you can do so with a simple environment variable, instead of editing the
163
163
  == Options
164
164
 
165
165
  Usage: annotate [options] [model_file]*
166
- --additional_file_patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
166
+ --additional-file-patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
167
167
  -d, --delete Remove annotations from all model files or the routes.rb file
168
168
  -p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
169
169
  --position
@@ -216,18 +216,18 @@ you can do so with a simple environment variable, instead of editing the
216
216
  --ignore-unknown-models don't display warnings for bad model files
217
217
  --with-comment include database comments in model annotations
218
218
 
219
- === Option: +additional_file_patterns+
219
+ === Option: +additional-file-patterns+
220
220
 
221
- CLI: +--additional_file_patterns+<br>
222
- Ruby: +:additional_file_patterns+
221
+ CLI: +--additional-file-patterns+<br>
222
+ Ruby: +:additional-file-patterns+
223
223
 
224
224
  Provide additional paths for the gem to annotate. These paths can include globs.
225
225
  It is recommended to use absolute paths. Here are some examples:
226
226
 
227
227
 
228
- - <code>/app/lib/decorates/%MODEL_NAME%/&ast;.rb</code>
229
- - <code>/app/lib/forms/%PLURALIZED_MODEL_NAME%/&ast;&ast;/&ast;.rb</code>
230
- - <code>/app/lib/forms/%TABLE_NAME%/&ast;.rb</code>
228
+ - <code>/app/lib/decorates/%MODEL_NAME%/*.rb</code>
229
+ - <code>/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb</code>
230
+ - <code>/app/lib/forms/%TABLE_NAME%/*.rb</code>
231
231
 
232
232
  The appropriate model will be inferred using the <code>%*%</code> syntax, annotating any matching files.
233
233
  It works with existing filename resolutions (options for which can be found in the +resolve_filename+ method of
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
26
26
  'lib/annotate/active_record_patch.rb',
27
27
  'lib/annotate/annotate_models.rb',
28
28
  'lib/annotate/annotate_routes.rb',
29
+ 'lib/annotate/constants.rb',
30
+ 'lib/annotate/parser.rb',
29
31
  'lib/annotate/tasks.rb',
30
32
  'lib/annotate/version.rb',
31
33
  'lib/generators/annotate/USAGE',
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
  require 'annotate/version'
5
5
  require 'annotate/annotate_models'
6
6
  require 'annotate/annotate_routes'
7
+ require 'annotate/constants'
7
8
 
8
9
  begin
9
10
  # ActiveSupport 3.x...
@@ -16,8 +17,6 @@ rescue StandardError
16
17
  end
17
18
 
18
19
  module Annotate
19
- TRUE_RE = /^(true|t|yes|y|1)$/i
20
-
21
20
  ##
22
21
  # The set of available options to customize the behavior of Annotate.
23
22
  #
@@ -107,15 +106,15 @@ module Annotate
107
106
  end
108
107
 
109
108
  def self.skip_on_migration?
110
- ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ TRUE_RE || ENV['skip_on_db_migrate'] =~ TRUE_RE
109
+ ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE
111
110
  end
112
111
 
113
112
  def self.include_routes?
114
- ENV['routes'] =~ TRUE_RE
113
+ ENV['routes'] =~ Constants::TRUE_RE
115
114
  end
116
115
 
117
116
  def self.include_models?
118
- ENV['models'] =~ TRUE_RE
117
+ ENV['models'] =~ Constants::TRUE_RE
119
118
  end
120
119
 
121
120
  def self.loaded_tasks=(val)
@@ -199,7 +198,7 @@ module Annotate
199
198
 
200
199
  def self.true?(val)
201
200
  return false if val.blank?
202
- return false unless val =~ TRUE_RE
201
+ return false unless val =~ Constants::TRUE_RE
203
202
  true
204
203
  end
205
204
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'bigdecimal'
4
4
 
5
- module AnnotateModels
6
- TRUE_RE = /^(true|t|yes|y|1)$/i
5
+ require 'annotate/constants'
7
6
 
7
+ module AnnotateModels
8
8
  # Annotate Models plugin use this header
9
9
  COMPAT_PREFIX = '== Schema Info'.freeze
10
10
  COMPAT_PREFIX_MD = '## Schema Info'.freeze
@@ -590,7 +590,7 @@ module AnnotateModels
590
590
 
591
591
  def matched_types(options)
592
592
  types = MATCHED_TYPES.dup
593
- types << 'admin' if options[:active_admin] =~ TRUE_RE && !types.include?('admin')
593
+ types << 'admin' if options[:active_admin] =~ Annotate::Constants::TRUE_RE && !types.include?('admin')
594
594
  types << 'additional_file_patterns' if options[:additional_file_patterns].present?
595
595
 
596
596
  types
@@ -0,0 +1,5 @@
1
+ module Annotate
2
+ module Constants
3
+ TRUE_RE = /^(true|t|yes|y|1)$/i.freeze
4
+ end
5
+ end
@@ -0,0 +1,251 @@
1
+ require 'optparse'
2
+
3
+ module Annotate
4
+ # Class for handling command line arguments
5
+ class Parser # rubocop:disable Metrics/ClassLength
6
+ def self.parse(args, env = {})
7
+ new(args, env).parse
8
+ end
9
+
10
+ attr_reader :args, :options, :env
11
+
12
+ ANNOTATION_POSITIONS = %w[before top after bottom].freeze
13
+ FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
14
+ EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
15
+ FORMAT_TYPES = %w[bare rdoc markdown].freeze
16
+
17
+ def initialize(args, env)
18
+ @args = args
19
+ @options = default_options
20
+ @env = env
21
+ end
22
+
23
+ def parse
24
+ # To split up because right now this method parses and commits
25
+ parser.parse!(args)
26
+
27
+ commit
28
+
29
+ options
30
+ end
31
+
32
+ private
33
+
34
+ def commit
35
+ env.each_pair do |key, value|
36
+ ENV[key] = value
37
+ end
38
+ end
39
+
40
+ def parser
41
+ OptionParser.new do |option_parser|
42
+ add_options_to_parser(option_parser)
43
+ end
44
+ end
45
+
46
+ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
47
+ has_set_position = {}
48
+ positions = ANNOTATION_POSITIONS
49
+
50
+ option_parser.banner = 'Usage: annotate [options] [model_file]*'
51
+
52
+ option_parser.on('--additional-file-patterns path1,path2,path3', Array, "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns|
53
+ ENV['additional_file_patterns'] = additional_file_patterns
54
+ end
55
+
56
+ option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
57
+ @options[:target_action] = :remove_annotations
58
+ end
59
+
60
+ option_parser.on('-p', '--position [before|top|after|bottom]', positions,
61
+ 'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
62
+ env['position'] = p
63
+
64
+ FILE_TYPE_POSITIONS.each do |key|
65
+ env[key] = p unless has_set_position[key]
66
+ end
67
+ end
68
+
69
+ option_parser.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
70
+ 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
71
+ env['position_in_class'] = p
72
+ has_set_position['position_in_class'] = true
73
+ end
74
+
75
+ option_parser.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
76
+ 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
77
+ env['position_in_factory'] = p
78
+ has_set_position['position_in_factory'] = true
79
+ end
80
+
81
+ option_parser.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
82
+ 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
83
+ env['position_in_fixture'] = p
84
+ has_set_position['position_in_fixture'] = true
85
+ end
86
+
87
+ option_parser.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
88
+ 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
89
+ env['position_in_test'] = p
90
+ has_set_position['position_in_test'] = true
91
+ end
92
+
93
+ option_parser.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
94
+ 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
95
+ env['position_in_routes'] = p
96
+ has_set_position['position_in_routes'] = true
97
+ end
98
+
99
+ option_parser.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
100
+ 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
101
+ env['position_in_serializer'] = p
102
+ has_set_position['position_in_serializer'] = true
103
+ end
104
+
105
+ option_parser.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
106
+ 'If --w option is used, the same text will be used as opening and closing') do |p|
107
+ env['wrapper'] = p
108
+ end
109
+
110
+ option_parser.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
111
+ env['wrapper_open'] = p
112
+ end
113
+
114
+ option_parser.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
115
+ env['wrapper_close'] = p
116
+ end
117
+
118
+ option_parser.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
119
+ env['routes'] = 'true'
120
+ end
121
+
122
+ option_parser.on('--models', "Annotate ActiveRecord models") do
123
+ env['models'] = 'true'
124
+ end
125
+
126
+ option_parser.on('-a', '--active-admin', 'Annotate active_admin models') do
127
+ env['active_admin'] = 'true'
128
+ end
129
+
130
+ option_parser.on('-v', '--version', 'Show the current version of this gem') do
131
+ puts "annotate v#{Annotate.version}"
132
+ @options[:exit] = true
133
+ end
134
+
135
+ option_parser.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
136
+ env['include_version'] = 'yes'
137
+ end
138
+
139
+ option_parser.on('-k', '--show-foreign-keys',
140
+ "List the table's foreign key constraints in the annotation") do
141
+ env['show_foreign_keys'] = 'yes'
142
+ end
143
+
144
+ option_parser.on('--ck',
145
+ '--complete-foreign-keys', 'Complete foreign key names in the annotation') do
146
+ env['show_foreign_keys'] = 'yes'
147
+ env['show_complete_foreign_keys'] = 'yes'
148
+ end
149
+
150
+ option_parser.on('-i', '--show-indexes',
151
+ "List the table's database indexes in the annotation") do
152
+ env['show_indexes'] = 'yes'
153
+ end
154
+
155
+ option_parser.on('-s', '--simple-indexes',
156
+ "Concat the column's related indexes in the annotation") do
157
+ env['simple_indexes'] = 'yes'
158
+ end
159
+
160
+ option_parser.on('--model-dir dir',
161
+ "Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
162
+ env['model_dir'] = dir
163
+ end
164
+
165
+ option_parser.on('--root-dir dir',
166
+ "Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
167
+ env['root_dir'] = dir
168
+ end
169
+
170
+ option_parser.on('--ignore-model-subdirects',
171
+ "Ignore subdirectories of the models directory") do |_dir|
172
+ env['ignore_model_sub_dir'] = 'yes'
173
+ end
174
+
175
+ option_parser.on('--sort',
176
+ "Sort columns alphabetically, rather than in creation order") do |_dir|
177
+ env['sort'] = 'yes'
178
+ end
179
+
180
+ option_parser.on('--classified-sort',
181
+ "Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |_dir|
182
+ env['classified_sort'] = 'yes'
183
+ end
184
+
185
+ option_parser.on('-R', '--require path',
186
+ "Additional file to require before loading models, may be used multiple times") do |path|
187
+ env['require'] = if !env['require'].blank?
188
+ env['require'] + ",#{path}"
189
+ else
190
+ path
191
+ end
192
+ end
193
+
194
+ option_parser.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
195
+ exclusions ||= EXCLUSION_LIST
196
+ exclusions.each { |exclusion| env["exclude_#{exclusion}"] = 'yes' }
197
+ end
198
+
199
+ option_parser.on('-f', '--format [bare|rdoc|markdown]', FORMAT_TYPES, 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
200
+ env["format_#{fmt}"] = 'yes'
201
+ end
202
+
203
+ option_parser.on('--force', 'Force new annotations even if there are no changes.') do |_force|
204
+ env['force'] = 'yes'
205
+ end
206
+
207
+ option_parser.on('--frozen', 'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
208
+ env['frozen'] = 'yes'
209
+ end
210
+
211
+ option_parser.on('--timestamp', 'Include timestamp in (routes) annotation') do
212
+ env['timestamp'] = 'true'
213
+ end
214
+
215
+ option_parser.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |_value|
216
+ env['trace'] = 'yes'
217
+ end
218
+
219
+ option_parser.on('-I', '--ignore-columns REGEX', "don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
220
+ env['ignore_columns'] = regex
221
+ end
222
+
223
+ option_parser.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
224
+ env['ignore_routes'] = regex
225
+ end
226
+
227
+ option_parser.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
228
+ env['hide_limit_column_types'] = values.to_s
229
+ end
230
+
231
+ option_parser.on('--hide-default-column-types VALUES', "don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
232
+ env['hide_default_column_types'] = values.to_s
233
+ end
234
+
235
+ option_parser.on('--ignore-unknown-models', "don't display warnings for bad model files") do |_values|
236
+ env['ignore_unknown_models'] = 'true'
237
+ end
238
+
239
+ option_parser.on('--with-comment', "include database comments in model annotations") do |_values|
240
+ env['with_comment'] = 'true'
241
+ end
242
+ end
243
+
244
+ def default_options
245
+ {
246
+ target_action: :do_annotations,
247
+ exit: false
248
+ }
249
+ end
250
+ end
251
+ end
@@ -1,5 +1,5 @@
1
1
  module Annotate
2
2
  def self.version
3
- '3.0.0'
3
+ '3.0.2'
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.0.0
4
+ version: 3.0.2
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: 2019-09-27 00:00:00.000000000 Z
15
+ date: 2019-09-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -81,6 +81,8 @@ files:
81
81
  - lib/annotate/active_record_patch.rb
82
82
  - lib/annotate/annotate_models.rb
83
83
  - lib/annotate/annotate_routes.rb
84
+ - lib/annotate/constants.rb
85
+ - lib/annotate/parser.rb
84
86
  - lib/annotate/tasks.rb
85
87
  - lib/annotate/version.rb
86
88
  - lib/generators/annotate/USAGE