Skip to content

Fix or workaround for duplicate exposure caveat? #56

Closed
@nickls

Description

@nickls

I'm looking to expose using different entities if a user is anonymous or not:

class MediaEntity < Grape::Entity
  expose :id
  expose :user, using: Entities::UserEntity, if: lambda { |object, options| object.anonymous == false }
  expose :user, using: Entities::AnonymousUserEntity, if: lambda { |object, options| object.anonymous == true }
end

present :data, media, with: MediaEntity

This doesn't work as you documented in the caveat section. Is there a good workaround?

Also, do you have a solution in mind for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions