-
Notifications
You must be signed in to change notification settings - Fork 152
Refactoring: extract exposures. #151
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
Conversation
At first glance this change may seem too big. But every move here is reasonable. |
But some problem is introduced with changing expose :x, using: E1, if: :condition1
expose :x, using: E2, if: :condition2 Which one should the swagger pick: I can help with implementing a workaround for swagger but for now I don't know exactly how to fix it. Maybe bring back construction of |
I'd like to merge this, it needs a detailed CHANGELOG entry and we have to discuss what to do about swagger. The conflicting cases should just have some predictable behavior. |
I just read through swagger specification and didn't find anything that might help gracefully solve this issue. But:
I'd like to propose a workaround to Any complains? |
No complaints. Grape-swagger needs a lot of work too and as long as we offer people a path forward I'm cool with it. Please at the very least open issues with grape-swagger for anything introduced here. |
1dba59e
to
76803a8
Compare
@marshall-lee Lets get this merged? Amend CHANGELOG? We also probably need an UPGRADING document. |
@dblock I'm working on CHANGELOG right now. And what format should I use in UPGRADING? |
0.5.0 makes sense |
Oops, JRuby build failed. https://travis-ci.org/intridea/grape-entity/builds/72464413 Latest changes revealed some misbehavior in JRuby, I reported it here: jruby/jruby#3178 |
LOL, Now Rubocop suggests me in https://travis-ci.org/intridea/grape-entity/jobs/72467983:
But |
But it's okay on |
@dblock I'm almost ready. Maybe you release 0.4.6 without these changes? Or just put all pending changes to 0.5.0? |
@marshall-lee You've done some great work here. I emailed you about becoming a maintainer on grape-entity. Your first order of duty could be to release 0.4.6? |
0983a92
to
050e965
Compare
This one reaches many goals at once: - Fixes ruby-grape#56. - `exposures` hash table is removed and substituted with `root_exposures` array. - Due to previous point, tree structure `nested_exposures` based on flat hash table with keys like `root_node__node__node` is removed because now double exposures don't rewrite previously defined so such tree structure is simply incorrect. `NestingExposure` with an array of children is introduced instead. - Ones who want an old rewriting behavior should manually `unexpose`. - Fixes ruby-grape#112. - Fixes ruby-grape#149: runtime `options` are now wrapped in an `Options` object. - Fixes ruby-grape#150: see new `spec/grape_entity/exposure_spec.rb`. - Fixes ruby-grape#152. - Fixes ruby-grape#153. - Fixes ruby-grape#155. - Fixes ruby-grape#156. - All exposure configuration and exposing strategies are extracted to the separate classes. - `key_for`, `name_for` internal methods are removed. - Much of the overhead is gone so performance is increased by 15-30%.
Refactoring: extract exposures.
👍 |
great stuff, too bad it breaks https://github.com/Gild/ruby-swagger too. How does the UPGRADE look like? next time pls deprecate the method first.. |
I think the line @calfzhou is referring to is: https://github.com/ruby-grape/grape-swagger/blob/03ee40d41d71063236c4b0b1d468f69978ab308e/lib/grape-swagger/doc_methods.rb#L261 |
ok this did the trick for me, super hacky, dirty and for sure not complete... class BaseDecorator < Grape::Entity
def self.exposures
extract_exposures(root_exposures, {})
end
private
def self.extract_exposures(root, hash, prefix = nil)
root.each do |entity|
key = "#{prefix}#{entity.attribute}"
nested = prefix.nil? ? {} : { nested: true }
if entity.is_a?(Grape::Entity::Exposure::NestingExposure)
hash[key.to_sym] = {}
extract_exposures(entity.nested_exposures, hash, key + '__')
else
hash[key.to_sym] = entity.send(:options).merge(nested)
end
end
hash
end
end |
@rngtng Want to give fixing ruby-grape/grape-swagger#314 a try? |
@dblock I'd love to, if I find the time...let me see.. |
This one reaches many goals at once:
exposures
hash table is removed and substituted withroot_exposures
array.nested_exposures
based onflat hash table with keys like
root_node__node__node
is removedbecause now double exposures don't rewrite previously defined
so such tree structure is simply incorrect.
NestingExposure
with an array of children is introduced instead.unexpose
.options
are now wrapped in anOptions
object.spec/grape_entity/exposure_spec.rb
.the separate classes.
key_for
,name_for
internal methods are removed.