Skip to content

Attribute options should allow send attribute_name to the method #125

@gbrlmrllo

Description

@gbrlmrllo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions