Class: FluentValidation::AttributeRule
- Inherits:
-
Object
- Object
- FluentValidation::AttributeRule
- Defined in:
- lib/fluent_validation/attribute_rule.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
Returns the value of attribute attribute_name.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
Instance Method Summary collapse
- #add_validator(validator) ⇒ Object
-
#initialize(&expression) ⇒ AttributeRule
constructor
A new instance of AttributeRule.
- #validate(object) ⇒ Object
Constructor Details
#initialize(&expression) ⇒ AttributeRule
10 11 12 13 |
# File 'lib/fluent_validation/attribute_rule.rb', line 10 def initialize(&expression) @expression = expression @validators = Array.new end |
Instance Attribute Details
#attribute_name ⇒ Object
Returns the value of attribute attribute_name.
8 9 10 |
# File 'lib/fluent_validation/attribute_rule.rb', line 8 def attribute_name @attribute_name end |
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/fluent_validation/attribute_rule.rb', line 8 def condition @condition end |
#error_code ⇒ Object
Returns the value of attribute error_code.
8 9 10 |
# File 'lib/fluent_validation/attribute_rule.rb', line 8 def error_code @error_code end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
7 8 9 |
# File 'lib/fluent_validation/attribute_rule.rb', line 7 def expression @expression end |
#validators ⇒ Object (readonly)
Returns the value of attribute validators.
7 8 9 |
# File 'lib/fluent_validation/attribute_rule.rb', line 7 def validators @validators end |
Instance Method Details
#add_validator(validator) ⇒ Object
15 16 17 |
# File 'lib/fluent_validation/attribute_rule.rb', line 15 def add_validator(validator) @validators << validator end |
#validate(object) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fluent_validation/attribute_rule.rb', line 19 def validate(object) validation_failures = Array.new if @condition.nil? || @condition.call(object) value = expression.call object validator_context = Validators::AttributeValidatorContext.new @attribute_name, value, @error_code @validators.each do |validator| result = validator.validate validator_context validation_failures.concat result end end validation_failures end |