Skip to content

Allow entity_name to be called on parent classes #794

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

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

urkle
Copy link
Contributor

@urkle urkle commented Jun 9, 2020

I am unsure why this limitation was done and issue #659 posses the same question.

This PR changes the behavior to allow calling entity_name if a parent class implements it.

My use case for this as follows

module Public::V2::Entities
   class Base < Grape::Entity
     # ... other shared logic
     def self.entity_name
       "V2::#{self.to_s.demodulize}"
     end
   end
   
   def MyEntity < Base
     # ....
   end
end

And I have ~ 20+ entities all inheriting from base and I don't really want the FULL module tree exposed in the API (in our application it is a little longer than what you see here). And being able to override entity_name once is significantly easier.

@coveralls
Copy link

coveralls commented Jun 9, 2020

Coverage Status

Coverage remained the same at 99.469% when pulling b1f6d22 on urkle:feat-interited-entity-name into 961e7ca on ruby-grape:master.

@urkle urkle force-pushed the feat-interited-entity-name branch from 0fe0a77 to 3054e03 Compare June 9, 2020 18:48
@grape-bot
Copy link

grape-bot commented Jun 9, 2020

1 Error
🚫 One of the lines below found in CHANGELOG.md doesn’t match the expected format. Please make it look like the other lines, pay attention to periods and spaces.
* [#794](https://github.com/ruby-grape/grape-swagger/pull/794): Allow entity_name to be inherited, fixes #659 - [@urkle](https://githubcom/urkle).

Generated by 🚫 danger

@urkle urkle force-pushed the feat-interited-entity-name branch from 3054e03 to fefb809 Compare June 9, 2020 19:08
Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

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

thanks @urkle … it seems this is always WIP … 😉

@urkle urkle force-pushed the feat-interited-entity-name branch from fefb809 to e2aa8ea Compare June 9, 2020 19:49
@LeFnord
Copy link
Member

LeFnord commented Jun 30, 2020

@urkle … please can you have a look on it, want have it in in trhe next release

@LeFnord LeFnord added the next release PRs for the next release label Jun 30, 2020
@urkle urkle force-pushed the feat-interited-entity-name branch from f0a0063 to b26a051 Compare July 1, 2020 18:04
@urkle urkle force-pushed the feat-interited-entity-name branch from b26a051 to b1f6d22 Compare July 1, 2020 18:17
@urkle
Copy link
Contributor Author

urkle commented Jul 1, 2020

@LeFnord I re-based retested and corrected the rubocop issues

@LeFnord
Copy link
Member

LeFnord commented Jul 1, 2020

cool thanks @urkle

@LeFnord LeFnord merged commit 3cb37fe into ruby-grape:master Jul 1, 2020
@urkle urkle deleted the feat-interited-entity-name branch June 22, 2021 14:44
aka-momo pushed a commit to aka-momo/grape-swagger that referenced this pull request Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next release PRs for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants