codenoble / cache-crispies

Speedy Rails JSON serialization with built-in caching
MIT License
156 stars 16 forks source link

Provide a way to camelize snakecase keys #52

Open wujibear opened 1 year ago

wujibear commented 1 year ago

I'm thinking this hasn't been made yet, but is there already (or would you be open to) a way to camelize serialized attribute keys?

For my own API, I want to refer to attributes in snakecase but would rather show those attributes in camelcase when sending to the client.

adamcrown commented 1 year ago

I left some feedback in the attached PR. This makes sense to me. Although, I wonder if it would be worth providing some out-of-the-box options too. Since I'm guessing 95% of the use cases for this would be camel case, pascal case or kebab case.

wujibear commented 1 year ago

I had thought of just taking a symbol for :snakecase, :camelcase, etc. but then I wasn't sure it would be evaluated within rails itself rather than ruby.

I figured a lambda/proc would be more explicit and avoid potential issues with it not having string translation methods.

wujibear commented 1 year ago

@adamcrown I've updated the PR with specs like you asked, did you have any other input for me on what you'd like to see?