Sha256: 82fec30ec6ce4c8d3978fe285de52365554d1c1e91eba3304d53bf6129718ae7

Contents?: true

Size: 874 Bytes

Versions: 13

Compression:

Stored size: 874 Bytes

Contents

module Lev

  # A collection of Error objects.  
  #
  class Errors < Array

    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

    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

    def [](key)
      self[key]
    end

    # Checks to see if the provided input is associated with one of the errors.
    def has_offending_input?(input)
      self.any? {|error| [error.offending_inputs].flatten.include? input}
    end

  protected

    def ignored_error_procs
      @ignored_error_procs ||= []
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lev-2.2.2 lib/lev/errors.rb
lev-4.0.0 lib/lev/errors.rb
lev-2.2.1 lib/lev/errors.rb
lev-2.2.0 lib/lev/errors.rb
lev-2.1.1 lib/lev/errors.rb
lev-2.1.0 lib/lev/errors.rb
lev-2.0.5 lib/lev/errors.rb
lev-2.0.4 lib/lev/errors.rb
lev-2.0.3 lib/lev/errors.rb
lev-2.0.2 lib/lev/errors.rb
lev-2.0.1 lib/lev/errors.rb
lev-1.0.1 lib/lev/errors.rb
lev-1.0.0 lib/lev/errors.rb