Class: Rack::Params::ArrayContext
- Defined in:
- lib/rack/params/context.rb
Overview
the DSL for validating an array parameter
Constant Summary
- Result =
Array
Instance Method Summary collapse
-
#every(type, options = {}) { ... } ⇒ Object
validate and coerce every element in the array, using the same values.
Constructor Details
This class inherits a constructor from Rack::Params::Context
Instance Method Details
#every(type, options = {}) { ... } ⇒ Object
validate and coerce every element in the array, using the same values. equivalent to HashContext#param over every element.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/rack/params/context.rb', line 195 def every(type, = {}, &block) params.each_with_index do |value, i| begin value = _coerce(value, type, ) # options.each { |v, vopts| _validate(i.to_s, value, v, vopts) } if block_given? value = _recurse(i.to_s, type, value, &block) result.errors.merge! value.errors end result[i] = value rescue ArgumentError => ex path = [@path, i].reject(&:nil?).join(".") result.errors[path] << ex. nil end end end |