Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Allow filtering params based on parent keys #13670

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
Contributor

gmalette commented Jan 11, 2014

Some parameters on APIs have ambiguous names
that cannot be filtered altogether.

For example, it makes sense not to filter :code in

{ file: { code: '<% source %>' }}

It makes sense however to filter it in

{ credit_card: { code: '424242424242' }}

This PR allows the use of lambda to achieve such
results.

gmalette added some commits Jan 10, 2014

@gmalette gmalette Allow filtering params based on parent keys
Some parameters on RESTful APIs have ambiguous names
that cannot be filtered altogether.

For example, it makes sense not to filter :code in

    { file: { code: '<% source %>' }}

It makes sense however to filter it in

    { credit_card: { code: '424242424242' }}

This PR allows the use of lambda to achieve such
results.
3a34667
@gmalette gmalette Tests that other values are not modified e8b37dd
Member

arthurnn commented Jan 13, 2014

I think we should provide the option to access to entire key path into the Proc, but I am still not 100% convinced about this API.

Contributor

gmalette commented Jan 13, 2014

I originally thought of having an API that used string and that would look more like:

config.filter_parameters += ["credit_card.code"]

but a form input can be named name="credit_card.code". If we were to use that approach, we could maybe filter both:

{ 'credit_card.code' => "[FILTERED]" }
{ :credit_card => { :code => "[FILTERED] }

Is this behaviour desirable?

As for Procs, we have to take into account that lambda can't be called with more arguments than it is defined for. If an application uses:

config.filter_parameters += [ lambda { |key, value| ... } ]

it cannot be called with the parents parameter. This is the reason for the for the arity check.

@gmalette gmalette closed this Aug 20, 2014

@gmalette gmalette deleted the gmalette:nested-parameter-filtering branch Aug 20, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment