-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add option to ignore property if instance is nil. #76
base: master
Are you sure you want to change the base?
Add option to ignore property if instance is nil. #76
Conversation
This is helpful when the property is a nested one and the associated representer expects a real instance, not a fragment.
I was thinking about that and had the idea that |
Thanks for the quick feedback. That sounds fine to us -- by introducing the new option we just tried to make the feature be backwards compatible, as we were not sure how people were using the fragment when there was no class or instance. Are you suggesting that We are not quite sure what you mean by the new Thanks, Jacobo & Chris |
Have you tried using |
Please, give me an example what you guys do in I have an idea for an upcoming feature in representable. Since we're pretty close in 1.8 to have a well-defined workflow for parsing and rendering, we could introduce a Here's an example, I just came up with this 15 minutes ago. instance: lambda { |fragment, args|
# find out what to do
args.flow.skip!(:serialize)
} That'll make it way more intuitive to control the flow. I see about 10 potential steps involved that could be managed with |
Hello! To your first question: we cannot use Which leads to the second question. In our XML we have a couple of fields that describe the subject that should be hydrated. One is an 'action' field, that will say something like 'add', 'update' or 'delete', and the other is an 'id' field, a regular database ID representing the record to be updated/deleted (does not apply to add)).
XML Examples:
Today we actually thought about this and felt that maybe we could achieve the same goal if I hope that was clear. Please let me know what your thoughts are! And thanks for your help. Cheers, Jacobo |
How do you access the |
This is helpful when the property is a nested one and the associated representer expects a real instance, not a fragment.
We have a scenario where we use the 'instance' option with a Proc that might return nil based on the original data being deserialized. In this case, we would like Representable to ignore the property, and not pass down the fragment to the associated representer.
With that property, we don't want FooRepresenter to call its setters with a fragment (we use XML and receive a Nokogiri::Node). The instance Proc already reviewed the fragment and decided that nothing had to be done.
We are happy to hear thoughts or suggestions.
Cheers!