toys 0.12.2 → 0.13.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CHANGELOG.md +35 -0
  4. data/LICENSE.md +1 -1
  5. data/README.md +7 -4
  6. data/builtins/system/git-cache.rb +238 -0
  7. data/builtins/system/test.rb +37 -2
  8. data/core-docs/toys/acceptor.rb +432 -0
  9. data/core-docs/toys/arg_parser.rb +397 -0
  10. data/core-docs/toys/cli.rb +493 -0
  11. data/core-docs/toys/compat.rb +2 -0
  12. data/core-docs/toys/completion.rb +329 -0
  13. data/core-docs/toys/context.rb +321 -0
  14. data/core-docs/toys/core.rb +14 -0
  15. data/core-docs/toys/dsl/base.rb +56 -0
  16. data/core-docs/toys/dsl/flag.rb +261 -0
  17. data/core-docs/toys/dsl/flag_group.rb +259 -0
  18. data/core-docs/toys/dsl/internal.rb +4 -0
  19. data/core-docs/toys/dsl/positional_arg.rb +139 -0
  20. data/core-docs/toys/dsl/tool.rb +1530 -0
  21. data/core-docs/toys/errors.rb +93 -0
  22. data/core-docs/toys/flag.rb +549 -0
  23. data/core-docs/toys/flag_group.rb +186 -0
  24. data/core-docs/toys/input_file.rb +8 -0
  25. data/core-docs/toys/loader.rb +222 -0
  26. data/core-docs/toys/middleware.rb +295 -0
  27. data/core-docs/toys/mixin.rb +142 -0
  28. data/core-docs/toys/module_lookup.rb +75 -0
  29. data/core-docs/toys/positional_arg.rb +145 -0
  30. data/core-docs/toys/settings.rb +507 -0
  31. data/core-docs/toys/source_info.rb +127 -0
  32. data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +49 -0
  33. data/core-docs/toys/standard_middleware/apply_config.rb +24 -0
  34. data/core-docs/toys/standard_middleware/handle_usage_errors.rb +33 -0
  35. data/core-docs/toys/standard_middleware/set_default_descriptions.rb +222 -0
  36. data/core-docs/toys/standard_middleware/show_help.rb +190 -0
  37. data/core-docs/toys/standard_middleware/show_root_version.rb +45 -0
  38. data/core-docs/toys/standard_mixins/bundler.rb +83 -0
  39. data/core-docs/toys/standard_mixins/exec.rb +645 -0
  40. data/core-docs/toys/standard_mixins/fileutils.rb +18 -0
  41. data/core-docs/toys/standard_mixins/gems.rb +48 -0
  42. data/core-docs/toys/standard_mixins/git_cache.rb +41 -0
  43. data/core-docs/toys/standard_mixins/highline.rb +133 -0
  44. data/core-docs/toys/standard_mixins/terminal.rb +135 -0
  45. data/core-docs/toys/standard_mixins/xdg.rb +49 -0
  46. data/core-docs/toys/template.rb +112 -0
  47. data/core-docs/toys/tool_definition.rb +926 -0
  48. data/core-docs/toys/utils/completion_engine.rb +49 -0
  49. data/core-docs/toys/utils/exec.rb +721 -0
  50. data/core-docs/toys/utils/gems.rb +185 -0
  51. data/core-docs/toys/utils/git_cache.rb +353 -0
  52. data/core-docs/toys/utils/help_text.rb +134 -0
  53. data/core-docs/toys/utils/terminal.rb +310 -0
  54. data/core-docs/toys/utils/xdg.rb +253 -0
  55. data/core-docs/toys/wrappable_string.rb +120 -0
  56. data/core-docs/toys-core.rb +63 -0
  57. data/docs/guide.md +497 -156
  58. data/lib/toys/standard_cli.rb +50 -36
  59. data/lib/toys/templates/clean.rb +18 -0
  60. data/lib/toys/templates/gem_build.rb +24 -0
  61. data/lib/toys/templates/minitest.rb +21 -0
  62. data/lib/toys/templates/rake.rb +23 -3
  63. data/lib/toys/templates/rdoc.rb +29 -0
  64. data/lib/toys/templates/rspec.rb +32 -4
  65. data/lib/toys/templates/rubocop.rb +14 -1
  66. data/lib/toys/templates/yardoc.rb +55 -0
  67. data/lib/toys/testing.rb +186 -109
  68. data/lib/toys/version.rb +1 -1
  69. data/lib/toys.rb +4 -2
  70. metadata +56 -6
@@ -0,0 +1,310 @@
1
+ begin
2
+ require "io/console"
3
+ rescue ::LoadError
4
+ # TODO: alternate methods of getting terminal size
5
+ end
6
+
7
+ module Toys
8
+ module Utils
9
+ ##
10
+ # **_Defined in the toys-core gem_**
11
+ #
12
+ # A simple terminal class.
13
+ #
14
+ # ### Styles
15
+ #
16
+ # This class supports ANSI styled output where supported.
17
+ #
18
+ # Styles may be specified in any of the following forms:
19
+ # * A symbol indicating the name of a well-known style, or the name of
20
+ # a defined style.
21
+ # * An rgb string in hex "rgb" or "rrggbb" form.
22
+ # * An ANSI code string in `\e[XXm` form.
23
+ # * An array of ANSI codes as integers.
24
+ #
25
+ class Terminal
26
+ ##
27
+ # **_Defined in the toys-core gem_**
28
+ #
29
+ # Fatal terminal error.
30
+ #
31
+ class TerminalError < ::StandardError
32
+ end
33
+
34
+ ##
35
+ # ANSI style code to clear styles
36
+ # @return [String]
37
+ #
38
+ CLEAR_CODE = "\e[0m"
39
+
40
+ ##
41
+ # Standard ANSI style codes by name.
42
+ # @return [Hash{Symbol => Array<Integer>}]
43
+ #
44
+ BUILTIN_STYLE_NAMES = {
45
+ clear: [0],
46
+ reset: [0],
47
+ bold: [1],
48
+ faint: [2],
49
+ italic: [3],
50
+ underline: [4],
51
+ blink: [5],
52
+ reverse: [7],
53
+ black: [30],
54
+ red: [31],
55
+ green: [32],
56
+ yellow: [33],
57
+ blue: [34],
58
+ magenta: [35],
59
+ cyan: [36],
60
+ white: [37],
61
+ on_black: [30],
62
+ on_red: [31],
63
+ on_green: [32],
64
+ on_yellow: [33],
65
+ on_blue: [34],
66
+ on_magenta: [35],
67
+ on_cyan: [36],
68
+ on_white: [37],
69
+ bright_black: [90],
70
+ bright_red: [91],
71
+ bright_green: [92],
72
+ bright_yellow: [93],
73
+ bright_blue: [94],
74
+ bright_magenta: [95],
75
+ bright_cyan: [96],
76
+ bright_white: [97],
77
+ on_bright_black: [100],
78
+ on_bright_red: [101],
79
+ on_bright_green: [102],
80
+ on_bright_yellow: [103],
81
+ on_bright_blue: [104],
82
+ on_bright_magenta: [105],
83
+ on_bright_cyan: [106],
84
+ on_bright_white: [107],
85
+ }.freeze
86
+
87
+ ##
88
+ # Default length of a single spinner frame, in seconds.
89
+ # @return [Float]
90
+ #
91
+ DEFAULT_SPINNER_FRAME_LENGTH = 0.1
92
+
93
+ ##
94
+ # Default set of spinner frames.
95
+ # @return [Array<String>]
96
+ #
97
+ DEFAULT_SPINNER_FRAMES = ["-", "\\", "|", "/"].freeze
98
+
99
+ ##
100
+ # Returns a copy of the given string with all ANSI style codes removed.
101
+ #
102
+ # @param str [String] Input string
103
+ # @return [String] String with styles removed
104
+ #
105
+ def self.remove_style_escapes(str)
106
+ # Source available in the toys-core gem
107
+ end
108
+
109
+ ##
110
+ # Create a terminal.
111
+ #
112
+ # @param input [IO,nil] Input stream.
113
+ # @param output [IO,Logger,nil] Output stream or logger.
114
+ # @param styled [Boolean,nil] Whether to output ansi styles. If `nil`, the
115
+ # setting is inferred from whether the output has a tty.
116
+ #
117
+ def initialize(input: $stdin, output: $stdout, styled: nil)
118
+ # Source available in the toys-core gem
119
+ end
120
+
121
+ ##
122
+ # Output stream or logger
123
+ # @return [IO,Logger,nil]
124
+ #
125
+ attr_reader :output
126
+
127
+ ##
128
+ # Input stream
129
+ # @return [IO,nil]
130
+ #
131
+ attr_reader :input
132
+
133
+ ##
134
+ # Whether output is styled
135
+ # @return [Boolean]
136
+ #
137
+ attr_reader :styled
138
+
139
+ ##
140
+ # Write a partial line without appending a newline.
141
+ #
142
+ # @param str [String] The line to write
143
+ # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
144
+ # partial line.
145
+ # @return [self]
146
+ #
147
+ def write(str = "", *styles)
148
+ # Source available in the toys-core gem
149
+ end
150
+
151
+ ##
152
+ # Read a line, blocking until one is available.
153
+ #
154
+ # @return [String] the entire string including the temrinating newline
155
+ # @return [nil] if the input is closed or at eof, or there is no input
156
+ #
157
+ def readline
158
+ # Source available in the toys-core gem
159
+ end
160
+
161
+ ##
162
+ # This method is defined so that `::Logger` will recognize a terminal as
163
+ # a log device target, but it does not actually close anything.
164
+ #
165
+ def close
166
+ # Source available in the toys-core gem
167
+ end
168
+
169
+ ##
170
+ # Write a line, appending a newline if one is not already present.
171
+ #
172
+ # @param str [String] The line to write
173
+ # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
174
+ # entire line.
175
+ # @return [self]
176
+ #
177
+ def puts(str = "", *styles)
178
+ # Source available in the toys-core gem
179
+ end
180
+ alias say puts
181
+
182
+ ##
183
+ # Write a line, appending a newline if one is not already present.
184
+ #
185
+ # @param str [String] The line to write
186
+ # @return [self]
187
+ #
188
+ def <<(str)
189
+ # Source available in the toys-core gem
190
+ end
191
+
192
+ ##
193
+ # Write a newline and flush the current line.
194
+ # @return [self]
195
+ #
196
+ def newline
197
+ # Source available in the toys-core gem
198
+ end
199
+
200
+ ##
201
+ # Ask a question and get a response.
202
+ #
203
+ # @param prompt [String] Required prompt string.
204
+ # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
205
+ # prompt.
206
+ # @param default [String,nil] Default value, or `nil` for no default.
207
+ # Uses `nil` if not specified.
208
+ # @param trailing_text [:default,String,nil] Trailing text appended to
209
+ # the prompt, `nil` for none, or `:default` to show the default.
210
+ # @return [String]
211
+ #
212
+ def ask(prompt, *styles, default: nil, trailing_text: :default)
213
+ # Source available in the toys-core gem
214
+ end
215
+
216
+ ##
217
+ # Confirm with the user.
218
+ #
219
+ # @param prompt [String] Prompt string. Defaults to `"Proceed?"`.
220
+ # @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
221
+ # prompt.
222
+ # @param default [Boolean,nil] Default value, or `nil` for no default.
223
+ # Uses `nil` if not specified.
224
+ # @return [Boolean]
225
+ #
226
+ def confirm(prompt = "Proceed? ", *styles, default: nil)
227
+ # Source available in the toys-core gem
228
+ end
229
+
230
+ ##
231
+ # Display a spinner during a task. You should provide a block that
232
+ # performs the long-running task. While the block is executing, a
233
+ # spinner will be displayed.
234
+ #
235
+ # @param leading_text [String] Optional leading string to display to the
236
+ # left of the spinner. Default is the empty string.
237
+ # @param frame_length [Float] Length of a single frame, in seconds.
238
+ # Defaults to {DEFAULT_SPINNER_FRAME_LENGTH}.
239
+ # @param frames [Array<String>] An array of frames. Defaults to
240
+ # {DEFAULT_SPINNER_FRAMES}.
241
+ # @param style [Symbol,Array<Symbol>] A terminal style or array of styles
242
+ # to apply to all frames in the spinner. Defaults to empty,
243
+ # @param final_text [String] Optional final string to display when the
244
+ # spinner is complete. Default is the empty string. A common practice
245
+ # is to set this to newline.
246
+ # @return [Object] The return value of the block.
247
+ #
248
+ def spinner(leading_text: "", final_text: "",
249
+ frame_length: nil, frames: nil, style: nil)
250
+ # Source available in the toys-core gem
251
+ end
252
+
253
+ ##
254
+ # Return the terminal size as an array of width, height.
255
+ #
256
+ # @return [Array(Integer,Integer)]
257
+ #
258
+ def size
259
+ # Source available in the toys-core gem
260
+ end
261
+
262
+ ##
263
+ # Return the terminal width
264
+ #
265
+ # @return [Integer]
266
+ #
267
+ def width
268
+ # Source available in the toys-core gem
269
+ end
270
+
271
+ ##
272
+ # Return the terminal height
273
+ #
274
+ # @return [Integer]
275
+ #
276
+ def height
277
+ # Source available in the toys-core gem
278
+ end
279
+
280
+ ##
281
+ # Define a named style.
282
+ #
283
+ # Style names must be symbols.
284
+ # The definition of a style may include any valid style specification,
285
+ # including the symbol names of existing defined styles.
286
+ #
287
+ # @param name [Symbol] The name for the style
288
+ # @param styles [Symbol,String,Array<Integer>...]
289
+ # @return [self]
290
+ #
291
+ def define_style(name, *styles)
292
+ # Source available in the toys-core gem
293
+ end
294
+
295
+ ##
296
+ # Apply the given styles to the given string, returning the styled
297
+ # string. Honors the styled setting; if styling is disabled, does not
298
+ # add any ANSI style codes and in fact removes any existing codes. If
299
+ # styles were added, ensures that the string ends with a clear code.
300
+ #
301
+ # @param str [String] String to style
302
+ # @param styles [Symbol,String,Array<Integer>...] Styles to apply
303
+ # @return [String] The styled string
304
+ #
305
+ def apply_styles(str, *styles)
306
+ # Source available in the toys-core gem
307
+ end
308
+ end
309
+ end
310
+ end
@@ -0,0 +1,253 @@
1
+ module Toys
2
+ module Utils
3
+ ##
4
+ # **_Defined in the toys-core gem_**
5
+ #
6
+ # A class that provides tools for working with the XDG Base Directory
7
+ # Specification.
8
+ #
9
+ # This class provides utility methods that locate base directories and
10
+ # search paths for application state, configuration, caches, and other
11
+ # data, according to the [XDG Base Directory Spec version
12
+ # 0.8](https://specifications.freedesktop.org/basedir-spec/0.8/).
13
+ #
14
+ # Tools can use the `:xdg` mixin for convenient access to this class.
15
+ #
16
+ # ### Example
17
+ #
18
+ # require "toys/utils/xdg"
19
+ #
20
+ # xdg = Toys::Utils::XDG.new
21
+ #
22
+ # # Get config file paths, in order from most to least inportant
23
+ # config_files = xdg.lookup_config("my-config.toml")
24
+ # config_files.each { |path| read_my_config(path) }
25
+ #
26
+ # ### Windows operation
27
+ #
28
+ # The Spec assumes a unix-like environment, and cannot be applied directly
29
+ # to Windows without modification. In general, this class will function on
30
+ # Windows, but with the following caveats:
31
+ #
32
+ # * All file paths must use Windows-style absolute paths, beginning with
33
+ # the drive letter.
34
+ # * Environment variables that can contain multiple paths (`XDG_*_DIRS`)
35
+ # use the Windows path delimiter (`;`) rather than the unix path
36
+ # delimiter (`:`).
37
+ # * Defaults for home directories (`XDG_*_HOME`) will follow unix
38
+ # conventions, using subdirectories under the user's profile directory
39
+ # rather than the Windows known folder paths.
40
+ # * Defaults for search paths (`XDG_*_DIRS`) will be empty and will not
41
+ # use the Windows known folder paths.
42
+ #
43
+ class XDG
44
+ ##
45
+ # Create an instance of XDG.
46
+ #
47
+ # @param env [Hash{String=>String}] the environment variables. Normally,
48
+ # you can omit this argument, as it will default to `::ENV`.
49
+ #
50
+ def initialize(env: ::ENV)
51
+ # Source available in the toys-core gem
52
+ end
53
+
54
+ ##
55
+ # Returns the absolute path to the current user's home directory.
56
+ #
57
+ # @return [String]
58
+ #
59
+ def home_dir
60
+ # Source available in the toys-core gem
61
+ end
62
+
63
+ ##
64
+ # Returns the absolute path to the single base directory relative to
65
+ # which user-specific data files should be written.
66
+ # Corresponds to the value of the `$XDG_DATA_HOME` environment variable
67
+ # and its defaults according to the XDG Base Directory Spec.
68
+ #
69
+ # @return [String]
70
+ #
71
+ def data_home
72
+ # Source available in the toys-core gem
73
+ end
74
+
75
+ ##
76
+ # Returns the absolute path to the single base directory relative to
77
+ # which user-specific configuration files should be written.
78
+ # Corresponds to the value of the `$XDG_CONFIG_HOME` environment variable
79
+ # and its defaults according to the XDG Base Directory Spec.
80
+ #
81
+ # @return [String]
82
+ #
83
+ def config_home
84
+ # Source available in the toys-core gem
85
+ end
86
+
87
+ ##
88
+ # Returns the absolute path to the single base directory relative to
89
+ # which user-specific state files should be written.
90
+ # Corresponds to the value of the `$XDG_STATE_HOME` environment variable
91
+ # and its defaults according to the XDG Base Directory Spec.
92
+ #
93
+ # @return [String]
94
+ #
95
+ def state_home
96
+ # Source available in the toys-core gem
97
+ end
98
+
99
+ ##
100
+ # Returns the absolute path to the single base directory relative to
101
+ # which user-specific non-essential (cached) data should be written.
102
+ # Corresponds to the value of the `$XDG_CACHE_HOME` environment variable
103
+ # and its defaults according to the XDG Base Directory Spec.
104
+ #
105
+ # @return [String]
106
+ #
107
+ def cache_home
108
+ # Source available in the toys-core gem
109
+ end
110
+
111
+ ##
112
+ # Returns the absolute path to the single base directory relative to
113
+ # which user-specific executable files may be written.
114
+ # Returns the value of `$HOME/.local/bin` as specified by the XDG Base
115
+ # Directory Spec.
116
+ #
117
+ # @return [String]
118
+ #
119
+ def executable_home
120
+ # Source available in the toys-core gem
121
+ end
122
+
123
+ ##
124
+ # Returns the set of preference ordered base directories relative to
125
+ # which data files should be searched, as an array of absolute paths.
126
+ # The array is ordered from most to least important, and does _not_
127
+ # include the data home directory.
128
+ # Corresponds to the value of the `$XDG_DATA_DIRS` environment variable
129
+ # and its defaults according to the XDG Base Directory Spec.
130
+ #
131
+ # @return [Array<String>]
132
+ #
133
+ def data_dirs
134
+ # Source available in the toys-core gem
135
+ end
136
+
137
+ ##
138
+ # Returns the set of preference ordered base directories relative to
139
+ # which configuration files should be searched, as an array of absolute
140
+ # paths. The array is ordered from most to least important, and does
141
+ # _not_ include the config home directory.
142
+ # Corresponds to the value of the `$XDG_CONFIG_DIRS` environment variable
143
+ # and its defaults according to the XDG Base Directory Spec.
144
+ #
145
+ # @return [Array<String>]
146
+ #
147
+ def config_dirs
148
+ # Source available in the toys-core gem
149
+ end
150
+
151
+ ##
152
+ # Returns the absolute path to the single base directory relative to
153
+ # which user-specific runtime files and other file objects should be
154
+ # placed. May return `nil` if no such directory could be determined.
155
+ #
156
+ # @return [String,nil]
157
+ #
158
+ def runtime_dir
159
+ # Source available in the toys-core gem
160
+ end
161
+
162
+ ##
163
+ # Searches the data directories for an object with the given relative
164
+ # path, and returns an array of absolute paths to all objects found in
165
+ # the data directories (i.e. in {#data_dirs} or {#data_home}), in order
166
+ # from most to least important.
167
+ #
168
+ # @param path [String] Relative path of the object to search for
169
+ # @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
170
+ # to find. You can specify any of the types defined by
171
+ # [File::Stat#ftype](https://ruby-doc.org/core/File/Stat.html#method-i-ftype),
172
+ # such as `file` or `directory`, or the special type `any`. Types can
173
+ # be specified as strings or the corresponding symbols. If this
174
+ # argument is not provided, the default of `file` is used.
175
+ # @return [Array<String>]
176
+ #
177
+ def lookup_data(path, type: :file)
178
+ # Source available in the toys-core gem
179
+ end
180
+
181
+ ##
182
+ # Searches the config directories for an object with the given relative
183
+ # path, and returns an array of absolute paths to all objects found in
184
+ # the config directories (i.e. in {#config_dirs} or {#config_home}), in
185
+ # order from most to least important.
186
+ #
187
+ # @param path [String] Relative path of the object to search for
188
+ # @param type [String,Symbol,Array<String,Symbol>] The type(s) of objects
189
+ # to find. You can specify any of the types defined by
190
+ # [File::Stat#ftype](https://ruby-doc.org/core/File/Stat.html#method-i-ftype),
191
+ # such as `file` or `directory`, or the special type `any`. Types can
192
+ # be specified as strings or the corresponding symbols. If this
193
+ # argument is not provided, the default of `file` is used.
194
+ # @return [Array<String>]
195
+ #
196
+ def lookup_config(path, type: :file)
197
+ # Source available in the toys-core gem
198
+ end
199
+
200
+ ##
201
+ # Returns the absolute path to a directory under {#data_home}, creating
202
+ # it if it doesn't already exist.
203
+ #
204
+ # @param path [String] The relative path to the subdir within the base
205
+ # data directory.
206
+ # @return [String] The absolute path to the subdir.
207
+ # @raise [Errno::EEXIST] If a non-directory already exists there
208
+ #
209
+ def ensure_data_subdir(path)
210
+ # Source available in the toys-core gem
211
+ end
212
+
213
+ ##
214
+ # Returns the absolute path to a directory under {#config_home}, creating
215
+ # it if it doesn't already exist.
216
+ #
217
+ # @param path [String] The relative path to the subdir within the base
218
+ # config directory.
219
+ # @return [String] The absolute path to the subdir.
220
+ # @raise [Errno::EEXIST] If a non-directory already exists there
221
+ #
222
+ def ensure_config_subdir(path)
223
+ # Source available in the toys-core gem
224
+ end
225
+
226
+ ##
227
+ # Returns the absolute path to a directory under {#state_home}, creating
228
+ # it if it doesn't already exist.
229
+ #
230
+ # @param path [String] The relative path to the subdir within the base
231
+ # state directory.
232
+ # @return [String] The absolute path to the subdir.
233
+ # @raise [Errno::EEXIST] If a non-directory already exists there
234
+ #
235
+ def ensure_state_subdir(path)
236
+ # Source available in the toys-core gem
237
+ end
238
+
239
+ ##
240
+ # Returns the absolute path to a directory under {#cache_home}, creating
241
+ # it if it doesn't already exist.
242
+ #
243
+ # @param path [String] The relative path to the subdir within the base
244
+ # cache directory.
245
+ # @return [String] The absolute path to the subdir.
246
+ # @raise [Errno::EEXIST] If a non-directory already exists there
247
+ #
248
+ def ensure_cache_subdir(path)
249
+ # Source available in the toys-core gem
250
+ end
251
+ end
252
+ end
253
+ end
@@ -0,0 +1,120 @@
1
+ module Toys
2
+ ##
3
+ # **_Defined in the toys-core gem_**
4
+ #
5
+ # A string intended for word-wrapped display.
6
+ #
7
+ class WrappableString
8
+ ##
9
+ # Create a wrapped string.
10
+ # @param string [String,Array<String>] The string or array of string
11
+ # fragments
12
+ #
13
+ def initialize(string = "")
14
+ # Source available in the toys-core gem
15
+ end
16
+
17
+ ##
18
+ # Returns the string fragments, i.e. the individual "words" for wrapping.
19
+ #
20
+ # @return [Array<String>]
21
+ #
22
+ attr_reader :fragments
23
+
24
+ ##
25
+ # Returns a new WrappaableString whose content is the concatenation of this
26
+ # WrappableString with another WrappableString.
27
+ #
28
+ # @param other [WrappableString]
29
+ # @return [WrappableString]
30
+ #
31
+ def +(other)
32
+ # Source available in the toys-core gem
33
+ end
34
+
35
+ ##
36
+ # Returns true if the string is empty (i.e. has no fragments)
37
+ # @return [Boolean]
38
+ #
39
+ def empty?
40
+ # Source available in the toys-core gem
41
+ end
42
+
43
+ ##
44
+ # Returns the string without any wrapping
45
+ # @return [String]
46
+ #
47
+ def string
48
+ # Source available in the toys-core gem
49
+ end
50
+ alias to_s string
51
+
52
+ ##
53
+ # Tests two wrappable strings for equality
54
+ # @param other [Object]
55
+ # @return [Boolean]
56
+ #
57
+ def ==(other)
58
+ # Source available in the toys-core gem
59
+ end
60
+ alias eql? ==
61
+
62
+ ##
63
+ # Returns a hash code for this object
64
+ # @return [Integer]
65
+ #
66
+ def hash
67
+ # Source available in the toys-core gem
68
+ end
69
+
70
+ ##
71
+ # Wraps the string to the given width.
72
+ #
73
+ # @param width [Integer,nil] Width in characters, or `nil` for infinite.
74
+ # @param width2 [Integer,nil] Width in characters for the second and
75
+ # subsequent lines, or `nil` to use the same as width.
76
+ #
77
+ # @return [Array<String>] Wrapped lines
78
+ #
79
+ def wrap(width, width2 = nil)
80
+ # Source available in the toys-core gem
81
+ end
82
+
83
+ ##
84
+ # Wraps an array of lines to the given width.
85
+ #
86
+ # @param strs [Array<WrappableString>] Array of strings to wrap.
87
+ # @param width [Integer,nil] Width in characters, or `nil` for infinite.
88
+ # @param width2 [Integer,nil] Width in characters for the second and
89
+ # subsequent lines, or `nil` to use the same as width.
90
+ #
91
+ # @return [Array<String>] Wrapped lines
92
+ #
93
+ def self.wrap_lines(strs, width, width2 = nil)
94
+ # Source available in the toys-core gem
95
+ end
96
+
97
+ ##
98
+ # Make the given object a WrappableString.
99
+ # If the object is already a WrappableString, return it. Otherwise,
100
+ # treat it as a string or an array of strings and wrap it in a
101
+ # WrappableString.
102
+ #
103
+ # @param obj [Toys::WrappableString,String,Array<String>]
104
+ # @return [Toys::WrappableString]
105
+ #
106
+ def self.make(obj)
107
+ # Source available in the toys-core gem
108
+ end
109
+
110
+ ##
111
+ # Make the given object an array of WrappableString.
112
+ #
113
+ # @param objs [Array<Toys::WrappableString,String,Array<String>>]
114
+ # @return [Array<Toys::WrappableString>]
115
+ #
116
+ def self.make_array(objs)
117
+ # Source available in the toys-core gem
118
+ end
119
+ end
120
+ end