Skip to content

Extended nested keys syntax to allow indexing into nested vectors #12

wants to merge 2 commits into from

2 participants

mw10013 commented Aug 8, 2012

A nested key that starts with '[' is passed to read-string and should return a vector. Numbers in that key vector are treated as indexes into nested vectors.

{"[:parents 0 :children 0 :grandchildren 0 :id]" "1"} => {:parents [{:children [{:grandchildren [{:id "1"}]}]}]}

This should have minimal impact on existing code since the existing parser takes "[parents]" and returns ["" "parents"], which seems to be a degenerate case.

{"[:parents 0 :children 0 :grandchildren 0 :id]" "1"
"[:parents 0 :children 0 :grandchildren 1 :id]" "2"
"[:parents 0 :children 1 :grandchildren 0 :id]" "3"
"[:parents 0 :children 0 :id]" "4"
"[:parents 0 :children 1 :id]" "5"
"[:parents 0 :id]" "6"}
=> {:parents
[{:id "6"
:children [{:id "4"
:grandchildren [{:id "1"} {:id "2"}]}
{:id "5"
:grandchildren [{:id "3"}]}]}]}

Official Ring Repositories member

Unfortunately this change is incompatible with the existing behaviour of wrap-nested-params, and therefore I don't think this pull request can be considered until Ring 2.0.0.

However, I'd encourage you to implement these ideas in a separate library. I definitely think wrap-nested-params can be improved upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.