toys 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 Daniel Azuma
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
- # IN THE SOFTWARE.
22
- ;
23
-
24
3
  module Toys
25
4
  module Templates
26
5
  ##
@@ -33,7 +12,7 @@ module Toys
33
12
  # Default version requirements for the yard gem.
34
13
  # @return [String]
35
14
  #
36
- DEFAULT_GEM_VERSION_REQUIREMENTS = "~> 0.9"
15
+ DEFAULT_GEM_VERSION_REQUIREMENTS = ["~> 0.9"].freeze
37
16
 
38
17
  ##
39
18
  # Default tool name
@@ -41,6 +20,18 @@ module Toys
41
20
  #
42
21
  DEFAULT_TOOL_NAME = "yardoc"
43
22
 
23
+ ##
24
+ # Default file globs
25
+ # @return [Array<String>]
26
+ #
27
+ DEFAULT_FILES = ["lib/**/*.rb"].freeze
28
+
29
+ ##
30
+ # Default output directory
31
+ # @return [String]
32
+ #
33
+ DEFAULT_OUTPUT_DIR = "doc"
34
+
44
35
  ##
45
36
  # Create the template settings for the Yardoc template.
46
37
  #
@@ -49,14 +40,15 @@ module Toys
49
40
  # @param gem_version [String,Array<String>] Version requirements for
50
41
  # the yard gem. Defaults to {DEFAULT_GEM_VERSION_REQUIREMENTS}.
51
42
  # @param files [Array<String>] An array of globs indicating the files
52
- # to document.
43
+ # to document. Defaults to {DEFAULT_FILES}.
53
44
  # @param generate_output [Boolean] Whether to generate output. Setting to
54
45
  # false causes yardoc to emit warnings/errors but not generate html.
55
46
  # Defaults to true.
56
47
  # @param generate_output_flag [Boolean] Whether to create a flag
57
48
  # `--[no-]output` that can control whether output is generated.
58
49
  # Defaults to false.
59
- # @param output_dir [String,nil] Output directory. Defaults to "doc".
50
+ # @param output_dir [String,nil] Output directory. Defaults to
51
+ # {DEFAULT_OUTPUT_DIR}.
60
52
  # @param fail_on_warning [Boolean] Whether the tool should return a
61
53
  # nonzero error code if any warnings happen. Defaults to false.
62
54
  # @param fail_on_undocumented_objects [Boolean] Whether the tool should
@@ -69,21 +61,27 @@ module Toys
69
61
  # @param hide_private_tag [Boolean] Hide methods with the `@private` tag.
70
62
  # Defaults to false.
71
63
  # @param readme [String,nil] Name of the readme file used as the title
72
- # page, or `nil` to use the default.
73
- # @param markup [String,nil] Markup style used in documentation. Defaults
74
- # to "rdoc".
75
- # @param template [String,nil] Template to use. Defaults to "default".
64
+ # page. If not provided, YARD will choose a default.
65
+ # @param markup [String,nil] Markup style used in documentation. If not
66
+ # provided, YARD will choose a default, likely "rdoc".
67
+ # @param template [String,nil] Template to use. If not provided, YARD
68
+ # will choose a default.
76
69
  # @param template_path [String,nil] The optional template path to look
77
70
  # for templates in.
78
- # @param format [String,nil] The output format for the template. Defaults
79
- # to "html".
71
+ # @param format [String,nil] The output format for the template. If not
72
+ # provided, YARD will choose a default, likely "html".
80
73
  # @param options [Array<String>] Additional options passed to YARD
81
- # @param stats_options [Array<String>] Additional options passed to YARD
82
- # stats
74
+ # @param stats_options [Array<String>] Additional stats options passed to
75
+ # YARD
76
+ # @param bundler [Boolean,Hash] If `false` (the default), bundler is not
77
+ # enabled for this tool. If `true` or a Hash of options, bundler is
78
+ # enabled. See the documentation for the
79
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
80
+ # for information on available options.
83
81
  #
84
82
  def initialize(name: nil,
85
83
  gem_version: nil,
86
- files: [],
84
+ files: nil,
87
85
  generate_output: true,
88
86
  generate_output_flag: false,
89
87
  output_dir: nil,
@@ -99,9 +97,10 @@ module Toys
99
97
  template_path: nil,
100
98
  format: nil,
101
99
  options: [],
102
- stats_options: [])
103
- @name = name || DEFAULT_TOOL_NAME
104
- @gem_version = gem_version || DEFAULT_GEM_VERSION_REQUIREMENTS
100
+ stats_options: [],
101
+ bundler: false)
102
+ @name = name
103
+ @gem_version = gem_version
105
104
  @files = files
106
105
  @generate_output = generate_output
107
106
  @generate_output_flag = generate_output_flag
@@ -119,27 +118,262 @@ module Toys
119
118
  @format = format
120
119
  @options = options
121
120
  @stats_options = stats_options
121
+ @bundler = bundler
122
+ end
123
+
124
+ ##
125
+ # Name of the tool to create.
126
+ #
127
+ # @param value [String]
128
+ # @return [String]
129
+ #
130
+ attr_writer :name
131
+
132
+ ##
133
+ # Version requirements for the rdoc gem.
134
+ # If set to `nil`, uses the bundled version if bundler is enabled, or
135
+ # defaults to {DEFAULT_GEM_VERSION_REQUIREMENTS} if bundler is not
136
+ # enabled.
137
+ #
138
+ # @param value [String,Array<String>,nil]
139
+ # @return [String,Array<String>,nil]
140
+ #
141
+ attr_writer :gem_version
142
+
143
+ ##
144
+ # An array of globs indicating which files to document.
145
+ #
146
+ # @param value [Array<String>]
147
+ # @return [Array<String>]
148
+ #
149
+ attr_writer :files
150
+
151
+ ##
152
+ # Whether to generate output. Setting to false causes yardoc to emit
153
+ # warnings/errors but not generate html.
154
+ #
155
+ # @param value [Boolean]
156
+ # @return [Boolean]
157
+ #
158
+ attr_writer :generate_output
159
+
160
+ ##
161
+ # Whether to create a flag `--[no-]output` that can control whether
162
+ # output is generated.
163
+ #
164
+ # @param value [Boolean]
165
+ # @return [Boolean]
166
+ #
167
+ attr_writer :generate_output_flag
168
+
169
+ ##
170
+ # Name of directory to receive html output files.
171
+ # If set to `nil`, defaults to {DEFAULT_OUTPUT_DIR}.
172
+ #
173
+ # @param value [String,nil]
174
+ # @return [String,nil]
175
+ #
176
+ attr_writer :output_dir
177
+
178
+ ##
179
+ # Whether the tool should return a nonzero error code if any warnings
180
+ # happen.
181
+ #
182
+ # @param value [Boolean]
183
+ # @return [Boolean]
184
+ #
185
+ attr_writer :fail_on_warning
186
+
187
+ ##
188
+ # Whether the tool should return a nonzero error code if any objects
189
+ # remain undocumented.
190
+ #
191
+ # @param value [Boolean]
192
+ # @return [Boolean]
193
+ #
194
+ attr_writer :fail_on_undocumented_objects
195
+
196
+ ##
197
+ # Whether to document public methods.
198
+ #
199
+ # @param value [Boolean]
200
+ # @return [Boolean]
201
+ #
202
+ attr_writer :show_public
203
+
204
+ ##
205
+ # Whether to document protected methods.
206
+ #
207
+ # @param value [Boolean]
208
+ # @return [Boolean]
209
+ #
210
+ attr_writer :show_protected
211
+
212
+ ##
213
+ # Whether to document private methods.
214
+ #
215
+ # @param value [Boolean]
216
+ # @return [Boolean]
217
+ #
218
+ attr_writer :show_private
219
+
220
+ ##
221
+ # Whether to hide methods with the `@private` tag.
222
+ #
223
+ # @param value [Boolean]
224
+ # @return [Boolean]
225
+ #
226
+ attr_writer :hide_private_tag
227
+
228
+ ##
229
+ # Name of the readme file used as the title page.
230
+ # If set to `nil`, YARD will choose a default.
231
+ #
232
+ # @param value [String,nil]
233
+ # @return [String,nil]
234
+ #
235
+ attr_writer :readme
236
+
237
+ ##
238
+ # Markup style used in documentation.
239
+ # If set to `nil`, YARD will choose a default, likely "rdoc".
240
+ #
241
+ # @param value [String,nil]
242
+ # @return [String,nil]
243
+ #
244
+ attr_writer :markup
245
+
246
+ ##
247
+ # Template to use.
248
+ # If set to `nil`, YARD will choose a default.
249
+ #
250
+ # @param value [String,nil]
251
+ # @return [String,nil]
252
+ #
253
+ attr_writer :template
254
+
255
+ ##
256
+ # Directory path to look for templates in.
257
+ # If set to `nil`, no additional template lookup paths will be used.
258
+ #
259
+ # @param value [String,nil]
260
+ # @return [String,nil]
261
+ #
262
+ attr_writer :template_path
263
+
264
+ ##
265
+ # Output format for the template.
266
+ # If set to `nil`, YARD will choose a default, likely "html".
267
+ #
268
+ # @param value [String,nil]
269
+ # @return [String,nil]
270
+ #
271
+ attr_writer :format
272
+
273
+ ##
274
+ # Additional options to pass to YARD
275
+ #
276
+ # @param value [Array<String>]
277
+ # @return [Array<String>]
278
+ #
279
+ attr_writer :options
280
+
281
+ ##
282
+ # Additional stats options to pass to YARD
283
+ #
284
+ # @param value [Array<String>]
285
+ # @return [Array<String>]
286
+ #
287
+ attr_writer :stats_options
288
+
289
+ ##
290
+ # Set the bundler state and options for this tool.
291
+ #
292
+ # Pass `false` to disable bundler. Pass `true` or a hash of options to
293
+ # enable bundler. See the documentation for the
294
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
295
+ # for information on the options that can be passed.
296
+ #
297
+ # @param value [Boolean,Hash]
298
+ # @return [Boolean,Hash]
299
+ #
300
+ attr_writer :bundler
301
+
302
+ ##
303
+ # Activate bundler for this tool.
304
+ #
305
+ # See the documentation for the
306
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
307
+ # for information on the options that can be passed.
308
+ #
309
+ # @param opts [keywords] Options for bundler
310
+ # @return [self]
311
+ #
312
+ def use_bundler(**opts)
313
+ @bundler = opts
314
+ self
315
+ end
316
+
317
+ # @private
318
+ attr_reader :generate_output
319
+ # @private
320
+ attr_reader :generate_output_flag
321
+ # @private
322
+ attr_reader :fail_on_warning
323
+ # @private
324
+ attr_reader :fail_on_undocumented_objects
325
+ # @private
326
+ attr_reader :show_public
327
+ # @private
328
+ attr_reader :show_protected
329
+ # @private
330
+ attr_reader :show_private
331
+ # @private
332
+ attr_reader :hide_private_tag
333
+ # @private
334
+ attr_reader :readme
335
+ # @private
336
+ attr_reader :markup
337
+ # @private
338
+ attr_reader :template
339
+ # @private
340
+ attr_reader :template_path
341
+ # @private
342
+ attr_reader :format
343
+ # @private
344
+ attr_reader :options
345
+ # @private
346
+ attr_reader :stats_options
347
+
348
+ # @private
349
+ def name
350
+ @name || DEFAULT_TOOL_NAME
122
351
  end
123
352
 
124
- attr_accessor :name
125
- attr_accessor :gem_version
126
- attr_accessor :files
127
- attr_accessor :generate_output
128
- attr_accessor :generate_output_flag
129
- attr_accessor :output_dir
130
- attr_accessor :fail_on_warning
131
- attr_accessor :fail_on_undocumented_objects
132
- attr_accessor :show_public
133
- attr_accessor :show_protected
134
- attr_accessor :show_private
135
- attr_accessor :hide_private_tag
136
- attr_accessor :readme
137
- attr_accessor :markup
138
- attr_accessor :template
139
- attr_accessor :template_path
140
- attr_accessor :format
141
- attr_accessor :options
142
- attr_accessor :stats_options
353
+ # @private
354
+ def gem_version
355
+ return Array(@gem_version) if @gem_version
356
+ @bundler ? [] : DEFAULT_GEM_VERSION_REQUIREMENTS
357
+ end
358
+
359
+ # @private
360
+ def files
361
+ @files ? Array(@files) : DEFAULT_FILES
362
+ end
363
+
364
+ # @private
365
+ def output_dir
366
+ @output_dir || DEFAULT_OUTPUT_DIR
367
+ end
368
+
369
+ # @private
370
+ def bundler_settings
371
+ if @bundler && !@bundler.is_a?(::Hash)
372
+ {}
373
+ else
374
+ @bundler
375
+ end
376
+ end
143
377
 
144
378
  on_expand do |template|
145
379
  tool(template.name) do
@@ -157,15 +391,16 @@ module Toys
157
391
  include :terminal
158
392
  include :gems
159
393
 
394
+ bundler_settings = template.bundler_settings
395
+ include :bundler, **bundler_settings if bundler_settings
396
+
160
397
  to_run do
161
- gem_requirements = Array(template.gem_version)
398
+ gem_requirements = template.gem_version
162
399
  gem "yard", *gem_requirements
163
400
 
164
401
  ::Dir.chdir(context_directory || ::Dir.getwd) do
165
402
  files = []
166
- patterns = Array(template.files)
167
- patterns = ["lib/**/*.rb"] if patterns.empty?
168
- patterns.each do |pattern|
403
+ template.files.each do |pattern|
169
404
  files.concat(::Dir.glob(pattern))
170
405
  end
171
406
  files.uniq!
@@ -1,30 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 Daniel Azuma
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
- # IN THE SOFTWARE.
22
- ;
23
-
24
3
  module Toys
25
4
  ##
26
5
  # Current version of the Toys command line executable.
27
6
  # @return [String]
28
7
  #
29
- VERSION = "0.9.4"
8
+ VERSION = "0.10.0"
30
9
  end