Class: Grape::Validations::AttributesIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/grape/validations/attributes_iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#scopeObject (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

#eachObject



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