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

ActiveModel::Serializer.setup(&config) not present in 0.10; causes failures in integrated gems #1770

Closed
augustosamame opened this issue Jun 2, 2016 · 4 comments

Comments

@augustosamame
Copy link

augustosamame commented Jun 2, 2016

It seems this issue has been changing back and forth.

Previous versions of AMS can be configured with this block in the initializer:

ActiveModel::Serializer.setup do |config|
config.adapter == :json_api
end

as opposed to the way indicate in the latest documentation:

ActiveModelSerializers.config.adapter = :json_api # Default: :attributes

current version (0.10.0) will fail when using the block with the following error:
undefined method `setup' for ActiveModel::Serializer:Class (NoMethodError)

The change is breaking integrations with other gems (like devise_token_auth see lynndylanhurley/devise_token_auth#644)

Is there a definitive answer to the proper syntax?

@bf4
Copy link
Member

bf4 commented Jun 2, 2016

well, the AMS version 0.8, 0.9, and 0.10 are all incompatible, so I'd argue it's the job of any gem supporting multiple versions to put any necessary conditionals in there.

If you want the old syntax, you could

ActiveModel::Serializer.instance_eval do
  def setup
    yield config
  end
end

but I wouldn't implement that since you can just

ActiveModelSerializers.config.tap do |c|
  c....
end

since config is essentially a hash, you could also just config.merge!

@bf4 bf4 changed the title Initializer syntax changing back and forth ActiveModel::Serializer.setup(&config) not present in 0.10; causes failures in integrated gems Jun 2, 2016
@augustosamame
Copy link
Author

Thanks. So in order to fix devise_token_auth I could just check if the ActiveModel::Serializer class responds to setup or config and configure accordingly?

@bf4
Copy link
Member

bf4 commented Jun 2, 2016

@augustosamame are you asking as a maintainer of devise_token_auth or someone who wants to work around its current incompatibility with 0.10.0

@bf4
Copy link
Member

bf4 commented Jun 2, 2016

@augustosamame why not let's discuss this in lynndylanhurley/devise_token_auth#644 (comment) where you're proposing a fix?

@bf4 bf4 closed this as completed Jun 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants