Class: TTY::Option::AggregateErrors
- Inherits:
-
Object
- Object
- TTY::Option::AggregateErrors
- Extended by:
- Forwardable
- Includes:
- Enumerable, UsageWrapper
- Defined in:
- lib/tty/option/aggregate_errors.rb
Instance Method Summary collapse
-
#add(error) ⇒ Object
Add error.
-
#each(&block) ⇒ Object
Enumerate each error.
-
#initialize(errors = []) ⇒ AggregateErrors
constructor
Create an intance from the passed error objects.
-
#messages ⇒ Object
All error messages.
-
#summary(width: 80, indent: 0) ⇒ String
Format errors for display in terminal.
Methods included from UsageWrapper
Constructor Details
#initialize(errors = []) ⇒ AggregateErrors
Create an intance from the passed error objects
19 20 21 |
# File 'lib/tty/option/aggregate_errors.rb', line 19 def initialize(errors = []) @errors = errors end |
Instance Method Details
#add(error) ⇒ Object
Add error
26 27 28 29 |
# File 'lib/tty/option/aggregate_errors.rb', line 26 def add(error) @errors << error error end |
#each(&block) ⇒ Object
Enumerate each error
40 41 42 |
# File 'lib/tty/option/aggregate_errors.rb', line 40 def each(&block) @errors.each(&block) end |
#messages ⇒ Object
All error messages
53 54 55 |
# File 'lib/tty/option/aggregate_errors.rb', line 53 def map(&:message) end |
#summary(width: 80, indent: 0) ⇒ String
Format errors for display in terminal
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tty/option/aggregate_errors.rb', line 72 def summary(width: 80, indent: 0) return "" if count.zero? output = [] space_indent = " " * indent if .count == 1 msg = .first label = "Error: " output << "#{space_indent}#{label}" \ "#{wrap(msg, indent: indent + label.length, width: width)}" else output << "#{space_indent}Errors:" .each_with_index do |, num| entry = " #{num + 1}) " output << "#{space_indent}#{entry}" \ "#{wrap(.capitalize, indent: indent + entry.length, width: width)}" end end output.join("\n") end |