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

Conditional Normalization #166

Merged
merged 5 commits into from
Jun 20, 2017

Conversation

Ross-Hunter
Copy link
Contributor

Allows an :if or :unless option to be passed to phony_normalize. Works with symbols that reference methods or lambdas, just like validations do.

More comprehensively fixes #149

I had the use case for an alarm that has a recipient, which can be an email or a phone number (sms), so I wanted to be able to conditionally normalize the recipient field - otherwise it would butcher an email address with numbers in it (see tests).

phony_normalize :recipient, default_country_code: 'US', if: -> { delivery_method == 'sms' }
phony_normalize :recipient, default_country_code: 'US', if: :sms_alarm?

The code is maybe a little more complex than I would like, but the alternative was to be very verbose because there is some nested conditional stuff (if with proc, unless with proc, if with symbol, unless with symbol).

Thanks!

@coveralls
Copy link

coveralls commented Jun 14, 2017

Coverage Status

Coverage increased (+0.006%) to 99.809% when pulling 2d75f88 on Ross-Hunter:feature/conditional-normalization into 4e0a3df on joost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 99.809% when pulling fad9f6e on Ross-Hunter:feature/conditional-normalization into 4e0a3df on joost:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 99.809% when pulling fad9f6e on Ross-Hunter:feature/conditional-normalization into 4e0a3df on joost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 99.809% when pulling 7422a3c on Ross-Hunter:feature/conditional-normalization into 4e0a3df on joost:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 99.809% when pulling 7422a3c on Ross-Hunter:feature/conditional-normalization into 4e0a3df on joost:master.

@joost
Copy link
Owner

joost commented Jun 16, 2017 via email

@joost joost merged commit aab3ab1 into joost:master Jun 20, 2017
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.

Make phony_normalize optional, on condition
3 participants