-
Notifications
You must be signed in to change notification settings - Fork 23
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
Allow to ignore invalid fields #28
Conversation
In some cases you do not want to loose all data if you have only one invalid field in encoded VCard (especially for multi-contact vcards). This change add two config parameters ::Vcard.configuration.raise_on_invalid_line (default true). When this parameter is set to true, decode will raise ::Vcard::InvalidEncodingError if found a field that encoded incorrectly (default behavior). When raise_on_invalid_line = false, exception will not be raised but field will be marked as invalid. With parameter ::Vcard.configuration.ignore_invalid_vcards you can define behavior for invalid fields. If ignore_invalid_vcards = true, then ::Vcard.decode will ignore a vcard that have at least one incorrect field. With ignore_invalid_vcards = false, vcard only invalid fields will be ignored, but vcard will be added to list, returned by .decode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @solenko! We really appreciate your contribution. I've edited your README
changes to fix the english and left a couple of comments for you to consider. Can you action those and them I'm happy to merge this.
@fields = [] | ||
|
||
fields.each do |f| | ||
raise ArgumentError, "fields must be an array of DirectoryInfo::Field objects" unless f.kind_of? DirectoryInfo::Field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a condition on this line regarding whether or not to raise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change behavior in this place. It looks for me like a strict type check and it's not clear for me why it needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
@ignore_invalid_vcard = true | ||
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this given there are no private methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thanks again Anton :) This is all merged now. @qoobaa, I can release a new gem version if you like. You just need to grant me access to Rubygems. |
@brendon done |
@solenko, this has been released as |
Thanks @qoobaa :) |
@brendon thank you for fast reaction and especially for fixes of my English :) |
You're welcome :) |
In some cases you do not want to loose all data if you have only one invalid field in encoded VCard (especially for multi-contact vcards).
This change add two config parameters
Vcard.configuration.raise_on_invalid_line (default true)
.When this parameter is set to true, decode will raise
Vcard::InvalidEncodingError
if found a field that encoded incorrectly (default behavior).When
raise_on_invalid_line = false
, exception will not be raised but field will be marked as invalid.With parameter
Vcard.configuration.ignore_invalid_vcards
you can define behavior for invalid fields.If
ignore_invalid_vcards = true
, thenVcard.decode
will ignore a vcard that have at least one incorrect field.With
ignore_invalid_vcards = false
, vcard only invalid fields will be ignored, but vcard will be added to list, returned by.decode