Class: Lev::Errors
Overview
A collection of Error objects.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(fail, args = {}) ⇒ Object
- #full_messages ⇒ Object
-
#has_offending_input?(input) ⇒ Boolean
Checks to see if the provided input is associated with one of the errors.
- #ignore(arg) ⇒ Object
-
#initialize(routine_status = nil, raise_fatal_errors = false) ⇒ Errors
constructor
A new instance of Errors.
- #raise_exception_if_any!(exception_type = StandardError) ⇒ Object
Constructor Details
#initialize(routine_status = nil, raise_fatal_errors = false) ⇒ Errors
Returns a new instance of Errors.
7 8 9 10 |
# File 'lib/lev/errors.rb', line 7 def initialize(routine_status = nil, raise_fatal_errors = false) @routine_status = routine_status || NullStatus.new @raise_fatal_errors = raise_fatal_errors end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/lev/errors.rb', line 43 def [](key) self[key] end |
#add(fail, args = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lev/errors.rb', line 12 def add(fail, args={}) args[:kind] ||= :lev error = Error.new(args) return if ignored_error_procs.any?{|proc| proc.call(error)} self.push(error) routine_status.add_error(error) if fail routine_status.failed! if raise_fatal_errors # Use special FatalError type so Routine doesn't re-add status errors raise Lev::FatalError, args.to_a.map { |i| i.join(' ') }.join(' - ') else throw :fatal_errors_encountered end end end |
#full_messages ⇒ Object
56 57 58 |
# File 'lib/lev/errors.rb', line 56 def map(&:full_message) end |
#has_offending_input?(input) ⇒ Boolean
Checks to see if the provided input is associated with one of the errors.
48 49 50 |
# File 'lib/lev/errors.rb', line 48 def has_offending_input?(input) self.any? {|error| [error.offending_inputs].flatten.include? input} end |
#ignore(arg) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/lev/errors.rb', line 33 def ignore(arg) proc = arg.is_a?(Symbol) ? Proc.new{|error| error.code == arg} : arg raise Lev.configuration.illegal_argument_error if !proc.respond_to?(:call) ignored_error_procs.push(proc) end |
#raise_exception_if_any!(exception_type = StandardError) ⇒ Object
52 53 54 |
# File 'lib/lev/errors.rb', line 52 def raise_exception_if_any!(exception_type = StandardError) raise exception_type, map(&:message).join('; ') if any? end |