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

Attribute options should allow send attribute_name to the method #125

Open
gbrlmrllo opened this issue Jun 11, 2019 · 1 comment
Open

Attribute options should allow send attribute_name to the method #125

gbrlmrllo opened this issue Jun 11, 2019 · 1 comment

Comments

@gbrlmrllo
Copy link

gbrlmrllo commented Jun 11, 2019

Hi guys, I had a problem when trying to do something like this

class GroupUserSerializer < ApplicationSerializer
  attributes = %i[example1 example2]
  attributes.each { |attr| attribute attr, if: :attr_authorized? }
  
 def attr_authorized?
   attr_name == :example2
 end

The problem is that mi method attr_authorized? doesn't have access to the name of the attr in the iteration.

Researching a little in the source code, I saw that the method in charge of executing the if option is should_include_attr?

It would be a good idea to allow to send the attribute_name, in case it is necessary like my case.

show_attr &&= send(if_method_name) if if_method_name

send(if_method_name, attribute_name)

@mwpastore
Copy link
Contributor

mwpastore commented Jun 11, 2019

We should probably send formatted_attribute_name and attr_data. EDIT: ...and to the unless method as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants