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

Adding if_any and unless_any validation conditions #13

Merged
merged 2 commits into from
Feb 18, 2016

Conversation

bitchef
Copy link
Contributor

@bitchef bitchef commented May 1, 2015

Hi,
I ran into a situation where I needed this functionality. Thought it would be a worthy addition to Vex.

A validation is applicable (or unapplicable) by using if and unless options. If given a list of conditions, the validation is applicable if all elements of the list evaluate to true whereas if_any and unless_any are triggered if at least one element of the list evaluates to true.

iex> Vex.Validator.validate?([name: "foo", state: "persisted"], if: [name: "foo", state: "new"])
false
iex> Vex.Validator.validate?([name: "foo", state: "persisted"], if_any: [name: "foo", state: "new"])
true

iex> Vex.Validator.validate?([name: "foo", state: "persisted"], unless: [name: "foo", state: "new"])
true
iex> Vex.Validator.validate?([name: "foo", state: "persisted"], unless_any: [name: "foo", state: "new"])
false

Hope it will be useful 😃

@bitchef bitchef changed the title Adding if_any and unless_any validation conditions Adding if_any and unless_any validation conditions May 1, 2015
benwilson512 added a commit that referenced this pull request Feb 18, 2016
Adding if_any and unless_any validation conditions
@benwilson512 benwilson512 merged commit df5d0dc into CargoSense:master Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants