Module: Snails::RequiredParams
- Defined in:
- lib/snails/app.rb
Instance Method Summary collapse
Instance Method Details
#requires!(req, hash = params) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/snails/app.rb', line 201 def requires!(req, hash = params) if req.is_a?(Hash) req.each do |k, vals| if vals.is_a?(Array) or vals.is_a?(Hash) halt(400, "Missing: #{k} in #{hash}") if hash[k].nil? requires!(vals, hash[k]) else requires!(k, hash) end end elsif req.nil? or (req.is_a?(Symbol) and hash[req].nil?) \ or (req.is_a?(Array) and req.any? { |p| hash[p].nil? }) halt(400, "Required parameters: #{req} (in #{hash})") end end |