Class: FlexValidations::All
- Inherits:
-
Object
- Object
- FlexValidations::All
- Defined in:
- lib/flex_validations/all.rb
Overview
Check if all elements in enumerable are valid
Defined Under Namespace
Classes: FailedMessage, NotEnumerableMessage, SuccessMessage
Instance Method Summary collapse
-
#initialize(validation) ⇒ All
constructor
A new instance of All.
- #to_s ⇒ String
- #validate(value) ⇒ FlexValidations::Result
Constructor Details
#initialize(validation) ⇒ All
Returns a new instance of All.
11 12 13 |
# File 'lib/flex_validations/all.rb', line 11 def initialize(validation) @validation = validation end |
Instance Method Details
#to_s ⇒ String
31 32 33 34 |
# File 'lib/flex_validations/all.rb', line 31 def to_s "all elements should pass following validation:\n" \ "#{IndentedString.new(@validation)}" end |
#validate(value) ⇒ FlexValidations::Result
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flex_validations/all.rb', line 18 def validate(value) return not_enumerable(value) unless value.respond_to?(:each, false) value.each.with_index do |element, index| res = @validation.validate(element) return failed(value, res, element, index) if res.fail? end success(value) end |