Module: Sinatra::Validation::Helpers

Defined in:
lib/herbert/Services.rb

Instance Method Summary collapse

Instance Method Details

#validate!(schema = nil) ⇒ Object

Only a few dragons here. This method validates body of the request against a schema. If no schema was passed to the method, it will try to find it automagically



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/herbert/Services.rb', line 73

def validate!(schema = nil)
  schema ||= Kernel.const_get(
    settings.validation[:module]
  ).const_get(
    /^\/(.*)\//.match(request.path)[1].capitalize
  ).const_get(
    request.env['REQUEST_METHOD'].downcase.capitalize
  )
  res = Kwalify::Validator.new(schema).validate(request.body)
  res.map! { |error|
    error.to_s
  }
  error(1012, nil, res) unless res == []
end