Class: Vanguard::Validator
- Inherits:
-
Object
- Object
- Vanguard::Validator
- Includes:
- Adamantium, Enumerable
- Defined in:
- lib/vanguard/validator.rb,
lib/vanguard/validator/builder.rb
Overview
Validator compsed from many rules
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#rules ⇒ Set<Rule>
readonly
private
Return rules.
Class Method Summary collapse
-
.build(&block) ⇒ Validator
private
Build validator.
Instance Method Summary collapse
-
#add(rule) ⇒ Validator
private
Return rules set with rule added.
-
#call(resource) ⇒ Result
private
Run validator on resource.
-
#each ⇒ self, Enumerator
private
Enumerate rules.
-
#on(attribute_name) ⇒ Enumerable<Rule>
private
Return rules on attribute name.
Instance Attribute Details
#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 rules
58 59 60 |
# File 'lib/vanguard/validator.rb', line 58 def rules @rules end |
Class Method Details
Instance Method Details
#add(rule) ⇒ Validator
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 rules set with rule added
36 37 38 |
# File 'lib/vanguard/validator.rb', line 36 def add(rule) self.class.new(rules.dup << rule) end |
#call(resource) ⇒ 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.
Run validator on resource
14 15 16 |
# File 'lib/vanguard/validator.rb', line 14 def call(resource) Result.new(self, resource) end |
#each ⇒ self, Enumerator
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.
Enumerate rules
70 71 72 73 74 75 76 |
# File 'lib/vanguard/validator.rb', line 70 def each return to_enum unless block_given? rules.each { |rule| yield rule } self end |
#on(attribute_name) ⇒ Enumerable<Rule>
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 rules on attribute name
48 49 50 |
# File 'lib/vanguard/validator.rb', line 48 def on(attribute_name) rules.select { |rule| rule.attribute_name == attribute_name } end |