Class: Kanpachi::ErrorList

Inherits:
Object
  • Object
show all
Defined in:
lib/kanpachi/error_list.rb

Overview

Class to keep track of all defined errors

Defined Under Namespace

Classes: DuplicateError

Instance Method Summary collapse

Constructor Details

#initializeErrorList

Returns a new instance of ErrorList.



8
9
10
# File 'lib/kanpachi/error_list.rb', line 8

def initialize
  @list = {}
end

Instance Method Details

#add(error) ⇒ Hash<Kanpachi::Error>

Add a error to the list

Parameters:

Returns:

Raises:

  • DuplicateError If a error is being duplicated.



34
35
36
37
38
39
# File 'lib/kanpachi/error_list.rb', line 34

def add(error)
  if @list.key? error.name
    raise DuplicateError, "An error named #{error.name} already exists"
  end
  @list[error.name] = error
end

#allArray<Kanpachi::Error>

Returns an array of errors

Returns:



24
25
26
# File 'lib/kanpachi/error_list.rb', line 24

def all
  @list.values
end

#find(name) ⇒ Nil, Kanpachi::Error

Returns a error based on its verb and url

Parameters:

  • name (String)

    The name of the error

Returns:



47
48
49
# File 'lib/kanpachi/error_list.rb', line 47

def find(name)
  @list[name]
end

#to_hashHash<Kanpachi::Error>

Returns a hash of errors

Returns:



16
17
18
# File 'lib/kanpachi/error_list.rb', line 16

def to_hash
  @list
end