module SimpleParams::Validations

Public Instance Methods

valid?(context = nil) click to toggle source
# File lib/simple_params/concerns/validations.rb, line 7
def valid?(context = nil)
  current_context, self.validation_context = validation_context, context
  errors.clear
  run_validations!

  # Make sure that nested classes are also valid
  nested_classes_valid? && errors.empty?
ensure
  self.validation_context = current_context
end
validate!() click to toggle source
# File lib/simple_params/concerns/validations.rb, line 18
def validate!
  unless valid?
    raise SimpleParamsError, self.errors.to_hash.to_s
  end
end

Private Instance Methods

nested_classes_valid?() click to toggle source
# File lib/simple_params/concerns/validations.rb, line 25
def nested_classes_valid?
  # Need to map them, THEN call all?, otherwise validations won't get run
  # on every nested class
  validations = all_nested_classes.map { |klass| klass.valid? }
  validations.all?
end