Class: Quiver::ErrorCollection
- Inherits:
-
Object
- Object
- Quiver::ErrorCollection
- Includes:
- Enumerable
- Defined in:
- lib/quiver/error_collection.rb
Instance Method Summary collapse
- #+(val) ⇒ Object
- #<<(val) ⇒ Object
- #==(other) ⇒ Object
- #add(val) ⇒ Object
- #each ⇒ Object
- #errors ⇒ Object
-
#initialize(initial = nil) ⇒ ErrorCollection
constructor
A new instance of ErrorCollection.
- #success? ⇒ Boolean
Constructor Details
#initialize(initial = nil) ⇒ ErrorCollection
Returns a new instance of ErrorCollection.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/quiver/error_collection.rb', line 5 def initialize(initial=nil) self.collection = [] if initial initial.each do |e| raise ArgumentError, 'initial must be an array of Quiver::Errors' unless e.is_a?(Quiver::Error) collection << e end end end |
Instance Method Details
#+(val) ⇒ Object
42 43 44 45 46 |
# File 'lib/quiver/error_collection.rb', line 42 def +(val) raise ArgumentError, 'rval must be a Quiver::ErrorCollection' unless val.is_a?(Quiver::ErrorCollection) Quiver::ErrorCollection.new(collection + val.errors) end |
#<<(val) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/quiver/error_collection.rb', line 26 def <<(val) if val.is_a?(Quiver::Error) collection << val else raise ArgumentError, 'arg must be a Quiver::Error' end end |
#==(other) ⇒ Object
52 53 54 |
# File 'lib/quiver/error_collection.rb', line 52 def ==(other) collection == other.send(:collection) end |
#add(val) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/quiver/error_collection.rb', line 34 def add(val) if val.is_a?(Quiver::ErrorCollection) collection.push(*val.errors) else raise ArgumentError, 'arg must be a Quiver::ErrorCollection' end end |
#each ⇒ Object
20 21 22 23 24 |
# File 'lib/quiver/error_collection.rb', line 20 def each collection.each do |e| yield e end end |
#errors ⇒ Object
16 17 18 |
# File 'lib/quiver/error_collection.rb', line 16 def errors collection.dup end |
#success? ⇒ Boolean
48 49 50 |
# File 'lib/quiver/error_collection.rb', line 48 def success? !collection.any? end |