class StValidation::Validators::UnionValidator

Checks if a value matches any of given blueprints

Public Class Methods

new(blueprint_list, factory) click to toggle source
# File lib/st_validation/validators/union_validator.rb, line 9
def initialize(blueprint_list, factory)
  # TODO: I think it's better to raise a different kind of error and transform it later
  raise InvalidBlueprintError if blueprint_list.empty?

  @validators = blueprint_list.map { |bp| factory.build(bp) }
end

Public Instance Methods

call(value) click to toggle source
# File lib/st_validation/validators/union_validator.rb, line 16
def call(value)
  @validators.any? { |v| v.call(value) }
end

Private Instance Methods

generate_explanation(value) click to toggle source
# File lib/st_validation/validators/union_validator.rb, line 22
def generate_explanation(value)
  @validators.map { |v| v.explain(value) }
end