-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
With params like this:
optional :captions, type: Array do
requires :output, type: String, value_set: ['cea608', 'cea708', 'dvbsub', 'teletext']
given output: ->(val) { val == 'cea608' } do
requires :language, type: String
requires :input_pid, type: String
end
given output: ->(val) { val == 'dvbsub' } do
requires :input_pid, type: String
end
end
grape has an exception. It's because of this code in lib/grape/validations/params_scope.rb
:
@dependent_on.each do |dependency|
if dependency.is_a?(Hash)
dependency_key = dependency.keys[0]
proc = dependency.values[0]
return false unless proc.call(params(parameters).try(:[], dependency_key))
elsif params(parameters).try(:[], dependency).blank?
return false
end
end if @dependent_on
Since parameters is an array here, and not a hash, it can't do []
since it wants an integer. This code needs to be amended to support arrays. From what I've been able to figure out on the code, the try(:[])
method should be applied to every item in the array params(parameters)
.
I'm looking at the spec tests in spec/grape/validations/params_scope_spec.rb
to try to figure out what to copy/paste so that I can work on implementing the behaviour. I guess lines 476 -> 586, but without the error conditions?