Skip to content
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

Move namespace of adapter to active model serializers #1499

Conversation

domitian
Copy link
Contributor

@domitian domitian commented Feb 6, 2016

#1446 will be fixed. Adapter moved from serializers to active_model_serializers namespace.

@bf4 need your help rebasing commits and coderefactoring.

@domitian
Copy link
Contributor Author

domitian commented Feb 6, 2016

Should I make code changes to make it pass for rubocop as well?

@bf4
Copy link
Member

bf4 commented Feb 7, 2016

Yup :)

Thanks!

B mobile phone

On Feb 6, 2016, at 10:39 AM, domitian [email protected] wrote:

Should I make code changes to make it pass for rubocop as well?


Reply to this email directly or view it on GitHub.

@domitian
Copy link
Contributor Author

domitian commented Feb 7, 2016

@bf4 all ci checks are fine.
But one thing I noticed is why didn't rubocop throw these offences when adapter is under ActiveModel::Serializer.
Then I noticed that the files which I made changes for are ignored in .rubocop_todo.yml here https://github.com/rails-api/active_model_serializers/blob/master/.rubocop_todo.yml#L16#L24
Since I made code changes to pass the CI instead of changing rubocop config, I don't know if it's the right thing to do. Need your suggestion on this.

@bf4
Copy link
Member

bf4 commented Feb 7, 2016

@domitian Thanks for this. I'm going to look it over a bit later. Also, heads up, I'd like to merge #1471 first and keep in mind the effect of this on other active adapter-specific prs...

@@ -3,6 +3,7 @@ module ActiveModel
class SerializableResource
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links])
include ActiveModelSerializers::Logging
require 'active_model_serializers/adapter'
Copy link
Member

Choose a reason for hiding this comment

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

any require you put the require here and not at the top?

@bf4
Copy link
Member

bf4 commented Feb 8, 2016

Looks good. Your thoughts re: #1499 (comment)

@@ -21,7 +21,7 @@ class Serializer
include Caching
include Links
include Type
require 'active_model/serializer/adapter'
require 'active_model_serializers/adapter'
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 this should be removed now, along with the adapter method (which I guess we can keep around with a deprecation warnings)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the adapter dependency and added adapter method with deprecation warning. To replace adapter method, I created a similar one in Adapter module called lookup_from_config. Can you look at the changes I made in the separate branch I made domitian/active_model_serializers@move-namespace-of-adapter-to-active-model-serializers...domitian:removing_adapter_from_serializer#diff-5849afc4f57a4ff11910f672112e293aR16

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 good. It has some extra spacing in one of the methods.

Maybe call it configured_adapter?

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 seems to be a good name.

@domitian
Copy link
Contributor Author

domitian commented Feb 9, 2016

@bf4
Made the namespace changes in docs as well, and added deprecation warning/message to requiring adapter inside serializer, renamed and added the adapter method in serializer to Adapter::configured_adapter.

I believe I made all the changes that are necessary for this PR, do you think are there any changes that needs to be done before I merge latest master into this branch(Seems to be lot of changes yesterday)?


There are two ways to register an adapter:

1) The simplest, is to subclass `ActiveModel::Serializer::Adapter::Base`, e.g. the below will
1) The simplest, is to subclass `ActiveModelSerializers::Adapter::Base`, e.g. the below will
register the `Example::UsefulAdapter` as `"example/useful_adapter"`.
Copy link
Member

Choose a reason for hiding this comment

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

Did you want example/useful_adapter quoted in the inline code block, or is just the code block sufficient in this context? "example/useful_adapter" vs example/useful_adapter

Copy link
Member

Choose a reason for hiding this comment

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

It's "example/useful_adapter", though it can be looked up as `:"example/useful_adapter" if you want

# code that registers the adapter `name` to the `klass`
 name = name.to_s.gsub(/\AActiveModel::Serializer::Adapter::/, ''.freeze)
 adapter_map.update(name.underscore => klass)

so, I think that's correct

@remear
Copy link
Member

remear commented Feb 22, 2016

Added a few comments. This looks good to me. 👍

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.

3 participants