Skip to content

Commit d4bcb54

Browse files
committed
Fix rubocop
1 parent 55661db commit d4bcb54

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

.rubocop_todo.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,31 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 2
10+
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
11+
Metrics/ClassLength:
12+
Exclude:
13+
- 'lib/grape/validations/params_scope.rb'
14+
915
# Offense count: 1
1016
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
17+
Metrics/CyclomaticComplexity:
18+
Exclude:
19+
- 'lib/grape/validations/types/hash_schema.rb'
20+
21+
# Offense count: 2
22+
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
1123
Metrics/MethodLength:
1224
Exclude:
1325
- 'lib/grape/endpoint.rb'
26+
- 'lib/grape/validations/types/hash_schema.rb'
27+
28+
# Offense count: 2
29+
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
30+
Metrics/PerceivedComplexity:
31+
Exclude:
32+
- 'lib/grape/validations/params_scope.rb'
33+
- 'lib/grape/validations/types/hash_schema.rb'
1434

1535
# Offense count: 18
1636
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* [#2665](https://github.com/ruby-grape/grape/pull/2665): Pass `attrs` directly to `AttributesIterator` instead of `validator` - [@ericproulx](https://github.com/ericproulx).
1111
* [#2657](https://github.com/ruby-grape/grape/pull/2657): Instantiate validators at definition time - [@ericproulx](https://github.com/ericproulx).
1212
* [#2667](https://github.com/ruby-grape/grape/pull/2667): Skip instrumentation in run_validators when no validators present - [@ericproulx](https://github.com/ericproulx).
13-
* [#](https://github.com/ruby-grape/grape/pull/xxx): Param with multiple acceptable Hash Types - [@jcagarcia](https://github.com/jcagarcia).
1413
* [#2661](https://github.com/ruby-grape/grape/pull/2661): Param with multiple acceptable Hash Types - [@jcagarcia](https://github.com/jcagarcia).
1514
* Your contribution here.
1615

lib/grape/validations/validators/multiple_hash_schema_validator.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ def validate_param!(attr_name, params)
2424

2525
# Try to validate against each schema and collect results
2626
results = []
27-
@schemas.each do |schema|
27+
valid_schema = @schemas.any? do |schema|
2828
result = schema.validate_hash(value, attr_name, @api, @scope)
2929
if result.valid?
30-
# Validation succeeded for this schema
31-
return
30+
true
31+
else
32+
results << result
33+
false
3234
end
33-
34-
results << result
3535
end
3636

37+
# Validation succeeded for one of the schemas
38+
return if valid_schema
39+
3740
# None of the schemas matched - determine best error message
3841
raise_best_error(attr_name, results)
3942
end

0 commit comments

Comments
 (0)