Class: Vanguard::Result
- Inherits:
-
Object
- Object
- Vanguard::Result
- Includes:
- Adamantium::Flat, Enumerable
- Defined in:
- lib/vanguard/result.rb
Overview
Result of a resource validation
Instance Attribute Summary collapse
-
#resource ⇒ Resource
readonly
private
Return resource.
-
#validator ⇒ Validator
readonly
private
Return validator.
Instance Method Summary collapse
-
#on(attribute_name) ⇒ Enumerable<Violation>
private
Return violations on attribute name.
-
#output ⇒ Object, Set<Violation>
private
The validation output.
-
#valid? ⇒ true, false
(also: #success?)
private
Test if result is valid.
-
#violations ⇒ Object
private
Return violations for resource.
Instance Attribute Details
#resource ⇒ Resource (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return resource
67 68 69 |
# File 'lib/vanguard/result.rb', line 67 def resource @resource end |
#validator ⇒ Validator (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return validator
75 76 77 |
# File 'lib/vanguard/result.rb', line 75 def validator @validator end |
Instance Method Details
#on(attribute_name) ⇒ Enumerable<Violation>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return violations on attribute name
57 58 59 |
# File 'lib/vanguard/result.rb', line 57 def on(attribute_name) violations.select { |violation| violation.attribute_name == attribute_name } end |
#output ⇒ Object, Set<Violation>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The validation output
45 46 47 |
# File 'lib/vanguard/result.rb', line 45 def output valid? ? resource : violations end |
#valid? ⇒ true, false Also known as: success?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test if result is valid
19 20 21 |
# File 'lib/vanguard/result.rb', line 19 def valid? violations.empty? end |
#violations ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return violations for resource
31 32 33 34 35 |
# File 'lib/vanguard/result.rb', line 31 def violations validator.rules.each_with_object(Set.new) do |rule, violations| violations.merge(rule.violations(resource)) end end |