Class: Kanpachi::ErrorList
- Inherits:
-
Object
- Object
- Kanpachi::ErrorList
- 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
-
#add(error) ⇒ Hash<Kanpachi::Error>
Add a error to the list.
-
#all ⇒ Array<Kanpachi::Error>
Returns an array of errors.
-
#find(name) ⇒ Nil, Kanpachi::Error
Returns a error based on its verb and url.
-
#initialize ⇒ ErrorList
constructor
A new instance of ErrorList.
-
#to_hash ⇒ Hash<Kanpachi::Error>
Returns a hash of errors.
Constructor Details
#initialize ⇒ ErrorList
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
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 |
#all ⇒ Array<Kanpachi::Error>
Returns an array of errors
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
47 48 49 |
# File 'lib/kanpachi/error_list.rb', line 47 def find(name) @list[name] end |
#to_hash ⇒ Hash<Kanpachi::Error>
Returns a hash of errors
16 17 18 |
# File 'lib/kanpachi/error_list.rb', line 16 def to_hash @list end |