Class: Rosette::Core::BufferedErrorReporter
- Inherits:
-
ErrorReporter
- Object
- ErrorReporter
- Rosette::Core::BufferedErrorReporter
- Defined in:
- lib/rosette/core/error_reporters/buffered_error_reporter.rb
Overview
Stores warnings errors in an internal buffer.
Instance Attribute Summary collapse
-
#errors ⇒ Array<Exception>
readonly
The list of collected errors.
-
#warnings ⇒ Array<Exception>
readonly
The list of collected warnings.
Instance Method Summary collapse
-
#each_error {|error, options| ... } ⇒ nil, Enumerator
Iterates over and yields each error.
-
#each_warning {|warning, options| ... } ⇒ nil, Enumerator
Iterates over and yields each warning.
-
#errors_found? ⇒ Boolean
Returns true if one or more errors has been added, false otherwise.
-
#initialize ⇒ BufferedErrorReporter
constructor
A new instance of BufferedErrorReporter.
-
#report_error(error, options = {}) ⇒ void
Add an error object to the list of collected errors.
-
#report_warning(error, options = {}) ⇒ void
Add an error object to the list of collected warnings.
-
#reset ⇒ void
Clears all errors and warnings.
-
#warnings_found? ⇒ Boolean
Returns true if one or more warnings has been added, false otherwise.
Methods inherited from ErrorReporter
Constructor Details
#initialize ⇒ BufferedErrorReporter
Returns a new instance of BufferedErrorReporter.
15 16 17 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 15 def initialize reset end |
Instance Attribute Details
#errors ⇒ Array<Exception> (readonly)
Returns the list of collected errors.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 12 class BufferedErrorReporter < ErrorReporter attr_reader :errors, :warnings def initialize reset end # Add an error object to the list of collected errors. # # @param [Exception] error The error object to add. # @param [Hash] options A hash of options to record with the error. # @return [void] def report_error(error, = {}) errors << { error: error, options: } end # Add an error object to the list of collected warnings. # # @param [Exception] error The error object to add. # @param [Hash] options A hash of options to record with the error. # @return [void] def report_warning(error, = {}) warnings << { error: error, options: } end # Clears all errors and warnings # # @return [void] def reset @errors = [] @warnings = [] end # Returns true if one or more errors has been added, false otherwise. # # @return [Boolean] Whether or not one or more errors have been added. def errors_found? errors.size > 0 end # Returns true if one or more warnings has been added, false otherwise. # # @return [Boolean] Whether or not one or more errors have been added. def warnings_found? warnings.size > 0 end # Iterates over and yields each error. If no block is given, returns # an +Enumerator+. # # @yield [error, options] each consecutive error and options hash. # @yieldparam warning [Exception] the error # @yieldparam options [Hash] the hash of options associated with +error+ # @return [nil, Enumerator] +nil+ if no block is given, an +Enumerator+ # otherwise. def each_error(&block) if block_given? errors.each do |error_hash| yield error_hash[:error], error_hash[:options] end else to_enum(__method__) end end # Iterates over and yields each warning. If no block is given, returns # an +Enumerator+. # # @yield [warning, options] each consecutive warning and options hash. # @yieldparam warning [Exception] the warning # @yieldparam options [Hash] the hash of options associated with +warning+ # @return [nil, Enumerator] +nil+ if no block is given, an +Enumerator+ def each_warning(&block) if block_given? warnings.each do |warning_hash| yield warning_hash[:error], warning_hash[:options] end else to_enum(__method__) end end end |
#warnings ⇒ Array<Exception> (readonly)
Returns the list of collected warnings.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 12 class BufferedErrorReporter < ErrorReporter attr_reader :errors, :warnings def initialize reset end # Add an error object to the list of collected errors. # # @param [Exception] error The error object to add. # @param [Hash] options A hash of options to record with the error. # @return [void] def report_error(error, = {}) errors << { error: error, options: } end # Add an error object to the list of collected warnings. # # @param [Exception] error The error object to add. # @param [Hash] options A hash of options to record with the error. # @return [void] def report_warning(error, = {}) warnings << { error: error, options: } end # Clears all errors and warnings # # @return [void] def reset @errors = [] @warnings = [] end # Returns true if one or more errors has been added, false otherwise. # # @return [Boolean] Whether or not one or more errors have been added. def errors_found? errors.size > 0 end # Returns true if one or more warnings has been added, false otherwise. # # @return [Boolean] Whether or not one or more errors have been added. def warnings_found? warnings.size > 0 end # Iterates over and yields each error. If no block is given, returns # an +Enumerator+. # # @yield [error, options] each consecutive error and options hash. # @yieldparam warning [Exception] the error # @yieldparam options [Hash] the hash of options associated with +error+ # @return [nil, Enumerator] +nil+ if no block is given, an +Enumerator+ # otherwise. def each_error(&block) if block_given? errors.each do |error_hash| yield error_hash[:error], error_hash[:options] end else to_enum(__method__) end end # Iterates over and yields each warning. If no block is given, returns # an +Enumerator+. # # @yield [warning, options] each consecutive warning and options hash. # @yieldparam warning [Exception] the warning # @yieldparam options [Hash] the hash of options associated with +warning+ # @return [nil, Enumerator] +nil+ if no block is given, an +Enumerator+ def each_warning(&block) if block_given? warnings.each do |warning_hash| yield warning_hash[:error], warning_hash[:options] end else to_enum(__method__) end end end |
Instance Method Details
#each_error {|error, options| ... } ⇒ nil, Enumerator
Iterates over and yields each error. If no block is given, returns an Enumerator.
67 68 69 70 71 72 73 74 75 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 67 def each_error(&block) if block_given? errors.each do |error_hash| yield error_hash[:error], error_hash[:options] end else to_enum(__method__) end end |
#each_warning {|warning, options| ... } ⇒ nil, Enumerator
Iterates over and yields each warning. If no block is given, returns an Enumerator.
84 85 86 87 88 89 90 91 92 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 84 def each_warning(&block) if block_given? warnings.each do |warning_hash| yield warning_hash[:error], warning_hash[:options] end else to_enum(__method__) end end |
#errors_found? ⇒ Boolean
Returns true if one or more errors has been added, false otherwise.
48 49 50 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 48 def errors_found? errors.size > 0 end |
#report_error(error, options = {}) ⇒ void
This method returns an undefined value.
Add an error object to the list of collected errors.
24 25 26 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 24 def report_error(error, = {}) errors << { error: error, options: } end |
#report_warning(error, options = {}) ⇒ void
This method returns an undefined value.
Add an error object to the list of collected warnings.
33 34 35 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 33 def report_warning(error, = {}) warnings << { error: error, options: } end |
#reset ⇒ void
This method returns an undefined value.
Clears all errors and warnings
40 41 42 43 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 40 def reset @errors = [] @warnings = [] end |
#warnings_found? ⇒ Boolean
Returns true if one or more warnings has been added, false otherwise.
55 56 57 |
# File 'lib/rosette/core/error_reporters/buffered_error_reporter.rb', line 55 def warnings_found? warnings.size > 0 end |