Class: Knight::Result
- Inherits:
-
Object
- Object
- Knight::Result
- Defined in:
- lib/knight/result.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
private
Return the resource.
-
#rules ⇒ Set(Rule)
readonly
private
Return the rule set.
Instance Method Summary collapse
-
#errors ⇒ Set(Error)
Return the result errors.
-
#initialize(resource, rules) ⇒ Result
constructor
private
Initialize a validation result.
-
#on(attribute) ⇒ Set(Error)
Return the errors for specific attribute.
-
#valid? ⇒ true, false
Check the result valid or not.
Constructor Details
#initialize(resource, rules) ⇒ Result
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.
Initialize a validation result
29 30 31 32 |
# File 'lib/knight/result.rb', line 29 def initialize(resource, rules) @resource = resource @rules = rules end |
Instance Attribute Details
#resource ⇒ Object (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 the resource
12 13 14 |
# File 'lib/knight/result.rb', line 12 def resource @resource end |
#rules ⇒ Set(Rule) (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 the rule set
19 20 21 |
# File 'lib/knight/result.rb', line 19 def rules @rules end |
Instance Method Details
#errors ⇒ Set(Error)
Return the result errors
63 64 65 66 67 68 |
# File 'lib/knight/result.rb', line 63 def errors rules.each_with_object(Set.new) do |rule, errors| error = attribute_check(rule) errors << error if error end end |
#on(attribute) ⇒ Set(Error)
Return the errors for specific attribute
82 83 84 |
# File 'lib/knight/result.rb', line 82 def on(attribute) errors.select { |error| error.attribute_name == attribute }.to_set end |
#valid? ⇒ true, false
Check the result valid or not
47 48 49 |
# File 'lib/knight/result.rb', line 47 def valid? errors.empty? end |