class FlexValidations::Or

Public Class Methods

new(*validations) click to toggle source
# File lib/flex_validations/or.rb, line 7
def initialize(*validations)
  @validations = validations
end

Public Instance Methods

to_s() click to toggle source

@return [String]

# File lib/flex_validations/or.rb, line 29
def to_s
  "any of validation should succeed:\n#{IndentedString.new(List.new(@validations))}"
end
validate(value) click to toggle source

@param value [Object] Value to be validated

@return [FlexValidations::Result]

# File lib/flex_validations/or.rb, line 14
def validate(value)
  fails = []

  @validations.each do |validation|
    res = validation.validate(value)

    return Result::Success::Composite.new(self, validation, res.message, value, res.raw) if res.success?

    fails.push(res)
  end

  Result::Fail::Simple.new(self, FailedMessage.new(fails), value, value)
end