Class: Quiver::ErrorCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/quiver/error_collection.rb

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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

#eachObject



20
21
22
23
24
# File 'lib/quiver/error_collection.rb', line 20

def each
  collection.each do |e|
    yield e
  end
end

#errorsObject



16
17
18
# File 'lib/quiver/error_collection.rb', line 16

def errors
  collection.dup
end

#success?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/quiver/error_collection.rb', line 48

def success?
  !collection.any?
end