-
Notifications
You must be signed in to change notification settings - Fork 70
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 default values for elements #51
Conversation
Thanks for the PR. I don't think that this should be enabled by default since this change is not backwards compatible. Someone might want nil values still be What do you think if instead of mapping default values with classes we provide a |
@krasnoukhov I think it will be quite less handy to use. We will need to duplicate default definition again and again. But, thinking about compatibility we can provide a global config options, named maybe We can override this options after requiring, same way as handler: require 'sax-machine'
SAXMachine.nil_default_values = false Also we need to provide warning in |
Ok, I see your point, but I must disagree. Why do you think that having non-nil values by default is a proper behavior? |
@krasnoukhov but |
I don't think that there should be an option to define default values on global level. In my opinion, such behavior is not obvious and might break a lot of things. For example, consider this code: https://github.com/feedjira/feedjira/blob/8d3cfb9ab4272cb4bb8c276479b921836bca10c7/lib/feedjira/parser/rss_feed_burner_entry.rb#L36 So, I'd go with What do you think? |
@krasnoukhov when you specified a type of element, for example an |
I don't think it's strange 😃 Consider following example: you're parsing XML request with sax-machine. You need to return error if your client missed to pass some of parameters. So you're checking for nil values and return error if there's any. Since empty String/Array/whatever might be valid argument in your XML call it would be really hard (impossible?) to distinguish between empty/nil values. Makes sense? |
@krasnoukhov good example. Ok. Lets add |
@krasnoukhov updated PR |
Ok, this looks good. Merging, but I'll adjust a code a bit. Thanks! ✨ |
Add default values for elements
No description provided.