Class: Grape::Validations::AttributesIterator
- Inherits:
-
Object
- Object
- Grape::Validations::AttributesIterator
- Includes:
- Enumerable
- Defined in:
- lib/grape/validations/attributes_iterator.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(validator, scope, params) ⇒ AttributesIterator
constructor
A new instance of AttributesIterator.
Constructor Details
#initialize(validator, scope, params) ⇒ AttributesIterator
Returns a new instance of AttributesIterator.
8 9 10 11 12 |
# File 'lib/grape/validations/attributes_iterator.rb', line 8 def initialize(validator, scope, params) @scope = scope @attrs = validator.attrs @params = Array.wrap(scope.params(params)) end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
6 7 8 |
# File 'lib/grape/validations/attributes_iterator.rb', line 6 def scope @scope end |
Instance Method Details
#each ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/grape/validations/attributes_iterator.rb', line 14 def each @params.each do |resource_params| @attrs.each_with_index do |attr_name, index| if resource_params.is_a?(Hash) && resource_params[attr_name].is_a?(Array) scope.index = index end yield resource_params, attr_name end end end |