toys 0.9.4 → 0.10.0

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.
@@ -1,25 +1,24 @@
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
- ;
3
+ require "toys/version"
4
+
5
+ # Add toys-core to the load path. The Toys debug scripts will set this
6
+ # environment variable explicitly, but in production, we get it from rubygems.
7
+ # We prepend to $LOAD_PATH directly rather than calling Kernel.gem, so that we
8
+ # don't get clobbered in case someone sets up bundler later.
9
+ ::ENV["TOYS_CORE_LIB_PATH"] ||= begin
10
+ path = ::File.expand_path("../../toys-core-#{::Toys::VERSION}/lib", __dir__)
11
+ unless path && ::File.directory?(path)
12
+ require "rubygems"
13
+ dep = ::Gem::Dependency.new("toys-core", "= #{::Toys::VERSION}")
14
+ path = dep.to_spec.full_require_paths.first
15
+ end
16
+ abort "Unable to find toys-core gem!" unless path && ::File.directory?(path)
17
+ path
18
+ end
19
+ $LOAD_PATH.unshift(::ENV["TOYS_CORE_LIB_PATH"])
20
+
21
+ require "toys-core"
23
22
 
24
23
  ##
25
24
  # Toys is a configurable command line tool. Write commands in config files
@@ -45,17 +44,6 @@ module Toys
45
44
  module Templates; end
46
45
  end
47
46
 
48
- require "toys/version"
49
-
50
- # Add toys-core to the load path. The Toys debug scripts will set this
51
- # environment variable explicitly, but in production, we get it from rubygems.
52
- # We prepend to $LOAD_PATH directly rather than calling Kernel.gem, so that we
53
- # don't get clobbered in case someone sets up bundler later.
54
- ::ENV["TOYS_CORE_LIB_PATH"] ||= begin
55
- dep = Gem::Dependency.new("toys-core", "= #{::Toys::VERSION}")
56
- dep.to_spec.full_require_paths.first
57
- end
58
- $LOAD_PATH.unshift(::ENV["TOYS_CORE_LIB_PATH"])
47
+ ::Toys.executable_path = ::Toys::EXECUTABLE_PATH
59
48
 
60
- require "toys-core"
61
49
  require "toys/standard_cli"
@@ -1,28 +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
- require "logger"
25
-
26
3
  module Toys
27
4
  ##
28
5
  # Subclass of `Toys::CLI` configured for the behavior of the standard Toys
@@ -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
  ##
@@ -43,13 +22,36 @@ module Toys
43
22
  # @param paths [Array<String>] An array of glob patterns indicating what
44
23
  # to clean.
45
24
  #
46
- def initialize(name: DEFAULT_TOOL_NAME, paths: [])
25
+ def initialize(name: nil, paths: [])
47
26
  @name = name
48
27
  @paths = paths
49
28
  end
50
29
 
51
- attr_accessor :name
52
- attr_accessor :paths
30
+ ##
31
+ # Name of the tool to create.
32
+ #
33
+ # @param value [String]
34
+ # @return [String]
35
+ #
36
+ attr_writer :name
37
+
38
+ ##
39
+ # An array of glob patterns indicating what to clean.
40
+ #
41
+ # @param value [Array<String>]
42
+ # @return [Array<String>]
43
+ #
44
+ attr_writer :paths
45
+
46
+ # @private
47
+ def paths
48
+ Array(@paths)
49
+ end
50
+
51
+ # @private
52
+ def name
53
+ @name || DEFAULT_TOOL_NAME
54
+ end
53
55
 
54
56
  on_expand do |template|
55
57
  tool(template.name) do
@@ -60,8 +62,7 @@ module Toys
60
62
  to_run do
61
63
  ::Dir.chdir(context_directory || ::Dir.getwd) do
62
64
  files = []
63
- patterns = Array(template.paths)
64
- patterns.each do |pattern|
65
+ template.paths.each do |pattern|
65
66
  files.concat(::Dir.glob(pattern))
66
67
  end
67
68
  files.uniq.each do |file|
@@ -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
  ##
@@ -42,16 +21,23 @@ module Toys
42
21
  #
43
22
  DEFAULT_OUTPUT_FLAGS = ["-o", "--output"].freeze
44
23
 
24
+ ##
25
+ # Default remote for pushing tags.
26
+ # @return [String]
27
+ #
28
+ DEFAULT_PUSH_REMOTE = "origin"
29
+
45
30
  ##
46
31
  # Create the template settings for the GemBuild template.
47
32
  #
48
33
  # @param name [String] Name of the tool to create. Defaults to
49
34
  # {DEFAULT_TOOL_NAME}.
50
35
  # @param gem_name [String] Name of the gem to build. If not provided,
51
- # defaults to the first gemspec file it finds.
36
+ # searches the context and current directories and uses the first
37
+ # gemspec file it finds.
52
38
  # @param output [String] Path to the gem package to generate. Optional.
53
- # If not provided, generates a default file name based on the gem
54
- # name and version, under the "pkg" directory.
39
+ # If not provided, defaults to a file name based on the gem name and
40
+ # version, under "pkg" in the current directory.
55
41
  # @param output_flags [Array<String>,true] Provide flags on the tool that
56
42
  # set the output path. Optional. If not provided, no flags are
57
43
  # created. You may set this to an array of flags (e.g. `["-o"]`) or
@@ -64,7 +50,7 @@ module Toys
64
50
  # a string. Otherwise, if the value is simply `true`, the "origin"
65
51
  # remote is used by default.
66
52
  #
67
- def initialize(name: DEFAULT_TOOL_NAME,
53
+ def initialize(name: nil,
68
54
  gem_name: nil,
69
55
  output: nil,
70
56
  output_flags: nil,
@@ -75,50 +61,138 @@ module Toys
75
61
  @name = name
76
62
  @gem_name = gem_name
77
63
  @output = output
78
- @output_flags = output_flags == true ? DEFAULT_OUTPUT_FLAGS : output_flags
64
+ @output_flags = output_flags
79
65
  @push_gem = push_gem
80
66
  @install_gem = install_gem
81
67
  @tag = tag
82
68
  @push_tag = push_tag
83
69
  end
84
70
 
85
- attr_accessor :name
86
- attr_accessor :gem_name
87
- attr_accessor :output
88
- attr_accessor :output_flags
89
- attr_accessor :push_gem
90
- attr_accessor :install_gem
91
- attr_accessor :tag
92
- attr_accessor :push_tag
71
+ ##
72
+ # Name of the tool to create.
73
+ #
74
+ # @param value [String]
75
+ # @return [String]
76
+ #
77
+ attr_writer :name
93
78
 
94
- on_expand do |template|
95
- unless template.gem_name
96
- candidates = ::Dir.chdir(context_directory || ::Dir.getwd) do
97
- ::Dir.glob("*.gemspec")
98
- end
99
- if candidates.empty?
100
- raise ToolDefinitionError, "Could not find a gemspec"
101
- end
102
- template.gem_name = candidates.first.sub(/\.gemspec$/, "")
79
+ ##
80
+ # Name of the gem to build. If `nil`, searches the context and current
81
+ # directories and uses the first gemspec file it finds.
82
+ #
83
+ # @param value [String,nil]
84
+ # @return [String,nil]
85
+ #
86
+ attr_writer :gem_name
87
+
88
+ ##
89
+ # Path to the gem package to generate. If `nil`, defaults to a file name
90
+ # based on the gem name and version, under "pkg" in the current directory.
91
+ #
92
+ # @param value [String,nil]
93
+ # @return [String,nil]
94
+ #
95
+ attr_writer :output
96
+
97
+ ##
98
+ # Flags that set the output path on the generated tool. If `nil`, no
99
+ # flags are generated. If set to `true`, {DEFAULT_OUTPUT_FLAGS} is used.
100
+ #
101
+ # @param value [Array<String>,true,nil]
102
+ # @return [Array<String>,true,nil]
103
+ #
104
+ attr_writer :output_flags
105
+
106
+ ##
107
+ # Whether the tool should push the gem to Rubygems.
108
+ #
109
+ # @param value [Boolean]
110
+ # @return [Boolean]
111
+ #
112
+ attr_writer :push_gem
113
+
114
+ ##
115
+ # Whether the tool should install the built gen locally.
116
+ #
117
+ # @param value [Boolean]
118
+ # @return [Boolean]
119
+ #
120
+ attr_writer :install_gem
121
+
122
+ ##
123
+ # Whether to tag the git repo with the gem version.
124
+ #
125
+ # @param value [Boolean]
126
+ # @return [Boolean]
127
+ #
128
+ attr_writer :tag
129
+
130
+ ##
131
+ # Whether to push the new tag to a git remote. This may be set to the
132
+ # name of the remote as a string, to `true` to use {DEFAULT_PUSH_REMOTE}
133
+ # by default, or to `false` to disable pushing.
134
+ #
135
+ # @param value [Boolean,String]
136
+ # @return [Boolean,String]
137
+ #
138
+ attr_writer :push_tag
139
+
140
+ # @private
141
+ attr_reader :output
142
+ # @private
143
+ attr_reader :push_gem
144
+ # @private
145
+ attr_reader :install_gem
146
+ # @private
147
+ attr_reader :tag
148
+
149
+ # @private
150
+ def name
151
+ @name || DEFAULT_TOOL_NAME
152
+ end
153
+
154
+ # @private
155
+ def gem_name
156
+ return @gem_name if @gem_name
157
+ candidates = ::Dir.glob("*.gemspec")
158
+ if candidates.empty?
159
+ raise ToolDefinitionError, "Could not find a gemspec"
103
160
  end
104
- task_names = []
105
- task_names << "Install" if template.install_gem
106
- task_names << "Release" if template.push_gem
107
- task_names = task_names.empty? ? "Build" : task_names.join(" and ")
161
+ candidates.first.sub(/\.gemspec$/, "")
162
+ end
163
+
164
+ # @private
165
+ def output_flags
166
+ @output_flags == true ? DEFAULT_OUTPUT_FLAGS : Array(@output_flags)
167
+ end
108
168
 
169
+ # @private
170
+ def push_tag
171
+ @push_tag == true ? DEFAULT_PUSH_REMOTE : @push_tag
172
+ end
173
+
174
+ # @private
175
+ def task_names
176
+ names = []
177
+ names << "Install" if @install_gem
178
+ names << "Release" if @push_gem
179
+ names.empty? ? "Build" : names.join(" and ")
180
+ end
181
+
182
+ on_expand do |template|
109
183
  tool(template.name) do
110
- desc "#{task_names} the gem: #{template.gem_name}"
184
+ desc "#{template.task_names} the gem: #{template.gem_name}"
111
185
 
112
186
  flag :yes, "-y", "--yes", desc: "Do not ask for interactive confirmation"
113
- if template.output_flags
187
+ if template.output_flags.empty?
188
+ static :output, template.output
189
+ else
114
190
  flag :output do
115
- flags(Array(template.output_flags).map { |f| "#{f} VAL" })
191
+ flags(template.output_flags.map { |f| "#{f} VAL" })
116
192
  desc "output gem with the given filename"
117
193
  default template.output
118
194
  complete_values :file_system
119
195
  end
120
- else
121
- static :output, template.output
122
196
  end
123
197
 
124
198
  include :exec, exit_on_nonzero_status: true
@@ -126,6 +200,7 @@ module Toys
126
200
  include :terminal
127
201
 
128
202
  to_run do
203
+ require "rubygems"
129
204
  require "rubygems/package"
130
205
  ::Dir.chdir(context_directory || ::Dir.getwd) do
131
206
  gem_name = template.gem_name
@@ -152,7 +227,6 @@ module Toys
152
227
  if template.tag
153
228
  exec(["git", "tag", "v#{version}"])
154
229
  if template.push_tag
155
- template.push_tag = "origin" if template.push_tag == true
156
230
  exec(["git", "push", template.push_tag, "v#{version}"])
157
231
  end
158
232
  end
@@ -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 minitest gem.
34
13
  # @return [Array<String>]
35
14
  #
36
- DEFAULT_GEM_VERSION_REQUIREMENTS = "~> 5.0"
15
+ DEFAULT_GEM_VERSION_REQUIREMENTS = ["~> 5.0"].freeze
37
16
 
38
17
  ##
39
18
  # Default tool name
@@ -59,13 +38,23 @@ module Toys
59
38
  # @param name [String] Name of the tool to create. Defaults to
60
39
  # {DEFAULT_TOOL_NAME}.
61
40
  # @param gem_version [String,Array<String>] Version requirements for
62
- # the minitest gem. Defaults to {DEFAULT_GEM_VERSION_REQUIREMENTS}.
41
+ # the minitest gem. Optional. If not provided, uses the bundled
42
+ # version if bundler is enabled, or defaults to
43
+ # {DEFAULT_GEM_VERSION_REQUIREMENTS} if bundler is not enabled.
63
44
  # @param libs [Array<String>] An array of library paths to add to the
64
45
  # ruby require path. Defaults to {DEFAULT_LIBS}.
65
46
  # @param files [Array<String>] An array of globs indicating the test
66
47
  # files to load. Defaults to {DEFAULT_FILES}.
48
+ # @param seed [Integer] The random seed, if any. Optional.
49
+ # @param verbose [Boolean] Whether to produce verbose output. Defaults to
50
+ # false.
67
51
  # @param warnings [Boolean] If true, runs tests with Ruby warnings.
68
52
  # Defaults to true.
53
+ # @param bundler [Boolean,Hash] If `false` (the default), bundler is not
54
+ # enabled for this tool. If `true` or a Hash of options, bundler is
55
+ # enabled. See the documentation for the
56
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
57
+ # for information on available options.
69
58
  #
70
59
  def initialize(name: nil,
71
60
  gem_version: nil,
@@ -73,23 +62,143 @@ module Toys
73
62
  files: nil,
74
63
  seed: nil,
75
64
  verbose: false,
76
- warnings: true)
77
- @name = name || DEFAULT_TOOL_NAME
78
- @gem_version = gem_version || DEFAULT_GEM_VERSION_REQUIREMENTS
79
- @libs = libs || DEFAULT_LIBS
80
- @files = files || DEFAULT_FILES
65
+ warnings: true,
66
+ bundler: false)
67
+ @name = name
68
+ @gem_version = gem_version
69
+ @libs = libs
70
+ @files = files
81
71
  @seed = seed
82
72
  @verbose = verbose
83
73
  @warnings = warnings
74
+ @bundler = bundler
84
75
  end
85
76
 
86
- attr_accessor :name
87
- attr_accessor :gem_version
88
- attr_accessor :libs
89
- attr_accessor :files
90
- attr_accessor :seed
91
- attr_accessor :verbose
92
- attr_accessor :warnings
77
+ ##
78
+ # Name of the tool to create.
79
+ #
80
+ # @param value [String]
81
+ # @return [String]
82
+ #
83
+ attr_writer :name
84
+
85
+ ##
86
+ # Version requirements for the minitest gem.
87
+ # If set to `nil`, uses the bundled version if bundler is enabled, or
88
+ # defaults to {DEFAULT_GEM_VERSION_REQUIREMENTS} if bundler is not
89
+ # enabled.
90
+ #
91
+ # @param value [String,Array<String>,nil]
92
+ # @return [String,Array<String>,nil]
93
+ #
94
+ attr_writer :gem_version
95
+
96
+ ##
97
+ # An array of library paths to add to the ruby require path.
98
+ # If set to `nil`, defaults to {DEFAULT_LIBS}.
99
+ #
100
+ # @param value [String,Array<String>,nil]
101
+ # @return [String,Array<String>,nil]
102
+ #
103
+ attr_writer :libs
104
+
105
+ ##
106
+ # An array of globs indicating the test files to load.
107
+ # If set to `nil`, defaults to {DEFAULT_FILES}.
108
+ #
109
+ # @param value [String,Array<String>,nil]
110
+ # @return [String,Array<String>,nil]
111
+ #
112
+ attr_writer :files
113
+
114
+ ##
115
+ # The random seed, or `nil` if not specified.
116
+ #
117
+ # @param value [Integer,nil]
118
+ # @return [Integer,nil]
119
+ #
120
+ attr_writer :seed
121
+
122
+ ##
123
+ # Whether to produce verbose output.
124
+ #
125
+ # @param value [Boolean]
126
+ # @return [Boolean]
127
+ #
128
+ attr_writer :verbose
129
+
130
+ ##
131
+ # Whether to run tests with Ruby warnings.
132
+ #
133
+ # @param value [Boolean]
134
+ # @return [Boolean]
135
+ #
136
+ attr_writer :warnings
137
+
138
+ ##
139
+ # Set the bundler state and options for this tool.
140
+ #
141
+ # Pass `false` to disable bundler. Pass `true` or a hash of options to
142
+ # enable bundler. See the documentation for the
143
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
144
+ # for information on the options that can be passed.
145
+ #
146
+ # @param value [Boolean,Hash]
147
+ # @return [Boolean,Hash]
148
+ #
149
+ attr_writer :bundler
150
+
151
+ ##
152
+ # Use bundler for this tool.
153
+ #
154
+ # See the documentation for the
155
+ # [bundler mixin](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
156
+ # for information on the options that can be passed.
157
+ #
158
+ # @param opts [keywords] Options for bundler
159
+ # @return [self]
160
+ #
161
+ def use_bundler(**opts)
162
+ @bundler = opts
163
+ self
164
+ end
165
+
166
+ # @private
167
+ attr_reader :seed
168
+ # @private
169
+ attr_reader :verbose
170
+ # @private
171
+ attr_reader :warnings
172
+
173
+ # @private
174
+ def name
175
+ @name || DEFAULT_TOOL_NAME
176
+ end
177
+
178
+ # @private
179
+ def libs
180
+ @libs ? Array(@libs) : DEFAULT_LIBS
181
+ end
182
+
183
+ # @private
184
+ def files
185
+ @files ? Array(@files) : DEFAULT_FILES
186
+ end
187
+
188
+ # @private
189
+ def gem_version
190
+ return Array(@gem_version) if @gem_version
191
+ @bundler ? [] : DEFAULT_GEM_VERSION_REQUIREMENTS
192
+ end
193
+
194
+ # @private
195
+ def bundler_settings
196
+ if @bundler && !@bundler.is_a?(::Hash)
197
+ {}
198
+ else
199
+ @bundler
200
+ end
201
+ end
93
202
 
94
203
  on_expand do |template|
95
204
  tool(template.name) do
@@ -98,6 +207,9 @@ module Toys
98
207
  include :exec
99
208
  include :gems
100
209
 
210
+ bundler_settings = template.bundler_settings
211
+ include :bundler, **bundler_settings if bundler_settings
212
+
101
213
  flag :seed, "-s", "--seed SEED",
102
214
  default: template.seed, desc: "Sets random seed."
103
215
  flag :warnings, "-w", "--[no-]warnings",
@@ -113,7 +225,7 @@ module Toys
113
225
  desc: "Paths to the tests to run (defaults to all tests)"
114
226
 
115
227
  to_run do
116
- gem "minitest", *Array(template.gem_version)
228
+ gem "minitest", *template.gem_version
117
229
 
118
230
  ::Dir.chdir(context_directory || ::Dir.getwd) do
119
231
  ruby_args = []