grape icon indicating copy to clipboard operation
grape copied to clipboard

Use param foo in default for bar

Open jamesarosen opened this issue 3 years ago • 1 comments

What I'd like to do:

params do
  requires :foo
  optional :bar, default: -> (other_params) { "bar from foo #{other_params[:foo]} }
end

or perhaps

params do
  requires :foo
  optional :bar, coerce: -> (bar_value, other_params) { "bar from foo #{other_params[:foo]} }
end

Unfortunately, neither default nor coerce seems to accept the other params as an argument. It may be possible to get them from self (which is a ParamsScope) within that block, but it's not obvious how.

jamesarosen avatar Dec 16 '22 22:12 jamesarosen

Does params[:foo] work? If not this is a great feature request. Note that circular dependencies might become possible 🤔

dblock avatar Dec 16 '22 22:12 dblock