Class: Lev::Errors

Inherits:
Array show all
Defined in:
lib/lev/errors.rb

Overview

A collection of Error objects.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



25
26
27
# File 'lib/lev/errors.rb', line 25

def [](key)
  self[key]
end

#add(fail, args = {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/lev/errors.rb', line 7

def add(fail, args={}) 
  args[:kind] ||= :lev
  error = Error.new(args)
  return if ignored_error_procs.any?{|proc| proc.call(error)}
  self.push(error)
  throw :fatal_errors_encountered if fail
end

#has_offending_input?(input) ⇒ Boolean

Checks to see if the provided input is associated with one of the errors.

Returns:

  • (Boolean)


30
31
32
# File 'lib/lev/errors.rb', line 30

def has_offending_input?(input)
  self.any? {|error| [error.offending_inputs].flatten.include? input}
end

#ignore(arg) ⇒ Object

Raises:

  • (IllegalArgument)


15
16
17
18
19
20
21
22
23
# File 'lib/lev/errors.rb', line 15

def ignore(arg)
  proc = arg.is_a?(Symbol) ?
           Proc.new{|error| error.code == arg} :
           arg
  
  raise IllegalArgument if !proc.respond_to?(:call)

  ignored_error_procs.push(proc)
end