Skip to content
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

Merged
merged 1 commit into from
Aug 1, 2014
Merged

Add default values for elements #51

merged 1 commit into from
Aug 1, 2014

Conversation

kirillplatonov
Copy link

No description provided.

@krasnoukhov
Copy link
Collaborator

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 nil.

What do you think if instead of mapping default values with classes we provide a default attribute on config, which could be specified for each element?

@kirillplatonov
Copy link
Author

@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 nil_default_values, and set it to true by default.

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 STDOUT. And after next major release, we can change the value of option nil_default_values to false out of the box. It will be flexible and absolutely compatible with previous versions.

@krasnoukhov
Copy link
Collaborator

Ok, I see your point, but I must disagree. Why do you think that having non-nil values by default is a proper behavior?

@kirillplatonov
Copy link
Author

@krasnoukhov but default option for each element it's very good idea. It will add flexibility for library, I will implement it when we decide what to do with compatibility.

@krasnoukhov
Copy link
Collaborator

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
Global default values enabled by default will break how feedjira is using sax-machine.

So, I'd go with default for each element. Yes, if you want all your elements have any custom default value you're required to put that option everywhere.

What do you think?

@kirillplatonov
Copy link
Author

@krasnoukhov when you specified a type of element, for example an Array, you expect that the this element will have same type as you specified after parsing. It works properly if library found element in XML, but if not, it returns a nil. And nil has another type, not correspond to Array.
This behaviour is really strange.

@krasnoukhov
Copy link
Collaborator

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?

@kirillplatonov
Copy link
Author

@krasnoukhov good example. Ok. Lets add default option for each element.

@kirillplatonov
Copy link
Author

@krasnoukhov updated PR

@krasnoukhov
Copy link
Collaborator

Ok, this looks good. Merging, but I'll adjust a code a bit. Thanks! ✨

krasnoukhov added a commit that referenced this pull request Aug 1, 2014
Add default values for elements
@krasnoukhov krasnoukhov merged commit 72dc8ef into pauldix:master Aug 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants