Class: Plinko::Validation
- Inherits:
-
Object
- Object
- Plinko::Validation
- Defined in:
- lib/plinko/validation.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, errors = []) ⇒ Validation
constructor
A new instance of Validation.
- #with(validator) ⇒ Object
Constructor Details
#initialize(value, errors = []) ⇒ Validation
Returns a new instance of Validation.
5 6 7 8 |
# File 'lib/plinko/validation.rb', line 5 def initialize(value, errors = []) self.value = value self.errors = errors end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/plinko/validation.rb', line 3 def errors @errors end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/plinko/validation.rb', line 3 def value @value end |
Instance Method Details
#with(validator) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/plinko/validation.rb', line 10 def with(validator) new_value, validation_errors = validator.validate(value) accumulated_errors = errors + Array(validation_errors) return Valid.new(new_value) if accumulated_errors.empty? Error.new(new_value, accumulated_errors) end |