Skip to content

Namespace separator setting for json-api and tests #1874

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

Merged
merged 14 commits into from
Aug 12, 2016

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Aug 5, 2016

  • Documentation
  • Type transform setting and transformer, name fixed in tests

@bf4 resolved #1609,
merged into master, and would like @remear and @youroff to review for any
changes, since I'm merging this after changes in the KeyTransform code were made.

based on: #1791

@mention-bot
Copy link

@NullVoxPopuli, thanks for your PR! By analyzing the annotation information on this pull request, we identified @dubadub, @groyoh and @remear to be potential reviewers

- [#1791](https://github.com/rails-api/active_model_serializers/pull/1791) (@bf4, @NullVoxPopuli)
- JSON API Type Transform functions independent of Key Transform.
- Added jsonapi_type_transform config option.
- Added jsonapi_namespace_separator config option.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the namespace separator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both, I think.
and that key_transform won't affect the type's key.

The new options could be configured to behave the old way, I'm pretty sure

@NullVoxPopuli
Copy link
Contributor Author

tests pass!

# transform('SomeClass', :underscore) => 'some_class'
# transform('some_class', :snake) => 'someClass'
# etc...
def transform(string, type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall asking this in an earlier revision but I'll ask again. Why is this transform method needed? Why not do it like

KeyTransform.send(transform(options), value)
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good idea! I'll do that! standby

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's legacy from the original impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait... isn't that method you point to implemented by this method?

require 'active_model_serializers/key_transform'
KeyTransform.send(transform(options), value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I originally wrote this module it did not include the transform method. https://github.com/rails-api/active_model_serializers/blob/3498647d1a07b9e8a183702bef53cf1ce8a76370/lib/active_model_serializers/key_transform.rb

It seems to have appeared in 913f396

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed. I was confused about which transform method we were talking.

I need to stop coding when I'm tired...

:embarassed:

@bf4 bf4 force-pushed the namespace_separator_setting branch from becdf10 to b5b4915 Compare August 12, 2016 14:56
@bf4
Copy link
Member

bf4 commented Aug 12, 2016

@NullVoxPopuli @youroff Updated PR to just be the namespace transform

@bf4
Copy link
Member

bf4 commented Aug 12, 2016

(Didn't benchmark..)

@NullVoxPopuli
Copy link
Contributor Author

Sweet! now it's no longer a breaking change! :-)

@bf4
Copy link
Member

bf4 commented Aug 12, 2016

Also added a few learnings about serializer coupling from #1857

@@ -2,11 +2,30 @@ module ActiveModelSerializers
module Adapter
class JsonApi
class ResourceIdentifier
def self.type_for(class_name, serializer_type = nil, transform_options = {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason for making a class method: tied too much logic to serializer instances make refactoring difficult, especially when, as demonstrated here, the actual serializer instance is not necessary for the transformation

see problems in #1857 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcomed change!

@bf4
Copy link
Member

bf4 commented Aug 12, 2016

Good to merge?

Looks like there should be two output 'ready for pr' issues

@NullVoxPopuli
Copy link
Contributor Author

@bf4 I'd say so. Nice work!

@bf4 bf4 merged commit 6de3f31 into rails-api:master Aug 12, 2016
@bf4 bf4 deleted the namespace_separator_setting branch August 12, 2016 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants