-
Notifications
You must be signed in to change notification settings - Fork 152
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
:safe option #140
Comments
Obviously README and implementation should match. I think attribute that doesn't exist vs. |
What is "cannot be evaluated" then? When it raises exception? It seems like this option wasn't intented for such things. I think it's implemented for exposing mixed collections of objects — some of them may have some attribute and some of them may not. If I want expose something optionally I would use For example: class E < Grape::Entity
expose :a, if: -> (obj,opts) { obj.respond_to? :a }
expose :b, safe: true
end
# ...
X = Struct.new(:a, :b)
Y = Struct.new(:a)
Z = Struct.new(:b)
# ...
E.represent(X.new(1,2), serializable: true) # should evaluate to { a: 1, b: 2 }
E.represent(Y.new(1), serializable: true) # should evaluate to { a: 1, b: nil }
E.represent(Z.new(2), serializable: true) # should evaluate to { b: 2 } because :a is conditional
E.represent(Object.new, serializable: true) # should evaluate to { b: nil } So I think |
Ok, makes sense, other than your fix in #142 what do you propose we do about this issue? |
This one solves many problems at once: - Fixes ruby-grape#140. For this one I changed specs a bit. It's breaking but I think it's worth it. - Fixes ruby-grape#142 differently because now `respond_to?(name, true)` stuff is incapsulated in `Delegator::PlainObject`. - Old `delegate_attribute` catched `NoMethodError` and re-raised it with custom message. It's incorrect because `NoMethodError` can occur deep inside in method call — this exception simply doesn't mean that attribute doesn't exist. - Solves the problem that object is checked to `is_a?(Hash)` and `respond_to?(:fetch, true)` multiple times. - Extracts delegating logic to separate delegator classes. - Removes constructing of `valid_exposures` at all — there's no need in this method now.
This one solves many problems at once: - Fixes ruby-grape#140. For this one I changed specs a bit. It's breaking but I think it's worth it. - Fixes ruby-grape#142 differently because now `respond_to?(name, true)` stuff is incapsulated in `Delegator::PlainObject`. - Old `delegate_attribute` catched `NoMethodError` and re-raised it with custom message. It's incorrect because `NoMethodError` can occur deep inside in method call — this exception simply doesn't mean that attribute doesn't exist. - Solves the problem that object is checked to `is_a?(Hash)` and `respond_to?(:fetch, true)` multiple times. - Extracts delegating logic to separate delegator classes. - Removes constructing of `valid_exposures` at all — there's no need in this method now.
This one solves many problems at once: - Fixes ruby-grape#140. For this one I changed specs a bit. It's breaking but I think it's worth it. - Fixes ruby-grape#142 differently because now `respond_to?(name, true)` stuff is incapsulated in `Delegator::PlainObject`. - Old `delegate_attribute` catched `NoMethodError` and re-raised it with custom message. It's incorrect because `NoMethodError` can occur deep inside in method call — this exception simply doesn't mean that attribute doesn't exist. - Solves the problem that object is checked to `is_a?(Hash)` and `respond_to?(:fetch, true)` multiple times. - Extracts delegating logic to separate delegator classes. - Removes constructing of `valid_exposures` at all — there's no need in this method now.
This one solves many problems at once: - Fixes ruby-grape#140. For this one I changed specs a bit. It's breaking but I think it's worth it. - Fixes ruby-grape#142 differently because now `respond_to?(name, true)` stuff is incapsulated in `Delegator::PlainObject`. - Old `delegate_attribute` catched `NoMethodError` and re-raised it with custom message. It's incorrect because `NoMethodError` can occur deep inside in method call — this exception simply doesn't mean that attribute doesn't exist. - Solves the problem that object is checked to `is_a?(Hash)` and `respond_to?(:fetch, true)` multiple times. - Extracts delegating logic to separate delegator classes. - Removes constructing of `valid_exposures` at all — there's no need in this method now.
This one solves many problems at once: - Fixes ruby-grape#140. For this one I changed specs a bit. It's breaking but I think it's worth it. - Fixes ruby-grape#142 differently because now `respond_to?(name, true)` stuff is incapsulated in `Delegator::PlainObject`. - Old `delegate_attribute` catched `NoMethodError` and re-raised it with custom message. It's incorrect because `NoMethodError` can occur deep inside in method call — this exception simply doesn't mean that attribute doesn't exist. - Solves the problem that object is checked to `is_a?(Hash)` and `respond_to?(:fetch, true)` multiple times. - Extracts delegating logic to separate delegator classes. - Removes constructing of `valid_exposures` at all — there's no need in this method now.
Hello!
Here's the excerpt from README:
However, such fields are not exposed as
nil
— they're simply not exposed. Moreover this is written in specs:Who's right — the README or the specs?
My opinion that this is a bug. If we say
expose
then it should be somehow exposed. Not exposing it is just surprising.@dblock
I want to fix it because this
:safe
thing stops me from fixing another bugs and it stops me even from reasoning about that bugs 😄 But what to fix — implementation+broken specs or just README ?The text was updated successfully, but these errors were encountered: