Class: Graphiti::SpecHelpers::ErrorsProxy
- Inherits:
-
Object
- Object
- Graphiti::SpecHelpers::ErrorsProxy
show all
- Includes:
- Enumerable
- Defined in:
- lib/graphiti/spec_helpers/errors_proxy.rb
Defined Under Namespace
Classes: Error
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ErrorsProxy.
39
40
41
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 39
def initialize(array)
@errors = array.map { |e| Error.new(e) }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &blk) ⇒ Object
63
64
65
66
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 63
def method_missing(id, *args, &blk)
matches = @errors.select { |e| e.attribute.to_sym == id }
matches.length == 1 ? matches[0] : matches
end
|
Instance Method Details
43
44
45
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 43
def [](key)
@errors[key]
end
|
#each(&blk) ⇒ Object
47
48
49
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 47
def each(&blk)
@errors.each(&blk)
end
|
51
52
53
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 51
def length
count
end
|
#respond_to_missing?(id, include_private = false) ⇒ Boolean
Any name is answered: an attribute with no matching error yields an empty
array rather than raising NoMethodError.
70
71
72
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 70
def respond_to_missing?(id, include_private = false)
true
end
|
55
56
57
58
59
60
61
|
# File 'lib/graphiti/spec_helpers/errors_proxy.rb', line 55
def to_h
{}.tap do |hash|
@errors.each do |e|
hash[e.attribute] = e.message
end
end
end
|