Module: Sinatra::Rabbit::Validator

Defined in:
lib/sinatra/rabbit/validator.rb

Defined Under Namespace

Classes: InvalidValue, RequiredParameter, ValidationError

Class Method Summary (collapse)

Class Method Details

+ (Object) validate!(current_params, operation_params)



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sinatra/rabbit/validator.rb', line 44

def self.validate!(current_params, operation_params)
  operation_params.select { |p| p.required? }.each do |p|
    unless current_params.keys.include?(p.name.to_s)
      raise RequiredParameter.new(p, current_params)
    end
  end
  operation_params.select { |p| p.enum? }.each do |p|
    if p.enum? and !p.values.include?(current_params[p.name.to_s])
      raise InvalidValue.new(p, current_params[p.name.to_s])
    end
  end
end