-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change camelize behavior #293
Change camelize behavior #293
Conversation
iex> camelize("alreadyCamelized") | ||
"alreadyCamelized" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation: New test to prove an already-camelized value will remain camelized.
@@ -109,12 +112,19 @@ defmodule JSONAPI.Utils.String do | |||
with words <- | |||
Regex.split( | |||
~r{(?<=[a-zA-Z0-9])[-_](?=[a-zA-Z0-9])}, | |||
to_string(value) | |||
to_string(value), | |||
trim: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation: Using trim: true
means we can remove the need to manually filter out the empty strings.
# If there is only one word, leave it as-is | ||
[word] -> | ||
word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation: This is the main change. Like the comment says, if we could not split the value into multiple words (i.e. there were no -
or _
delimiters) then return the single word without downcasing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great; thanks! I am comfortable considering this a bug fix; I can't imagine anyone would consider the current behavior of "lowercasing when already camalized" a feature.
It would help if you bumped the version in the mix.exs file to 1.5.1
as part of this PR because it can currently take quite a while to get version-bump PRs merged which could delay us getting this fix into a release!
@mattpolzin Bumped the version! Thanks for your comment. |
👋 I have a view which has a field which I treat as an "opaque object" which I store as a
map
. Something like this:In my postgres database, an example value looks something like (note the camelCased
localizedAddress
field):The problem is that after this data flows out of my view, the resulting payload looks like this, where the
localizedAddress
key has becomelocalizedaddress
:I have pinned it down to the
String
module:If changing the
String
module is too disruptive/risky, then I think there should be a new callback in the view that is a mechanism for giving a value for a field, but without any further transformations applied to it. I.e. today if I do this: