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

Make .validators_on accept :kind option #7826

Merged
merged 1 commit into from Oct 3, 2012

Conversation

sikachu
Copy link
Member

@sikachu sikachu commented Oct 3, 2012

Making ActiveModel::Validators#validators_on to accept a :kind option which will filter out the validators on a particular attribute based on its kind.

Person.validators_on(:name)
# => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
# #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}>]

Person.validators_on(:name, :presence)
# => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>]

# => [#<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
# #<ActiveModel::Validations::InclusionValidator:0x007fe603bb8780 @attributes=[:age], @options={:in=>0..99}>]

Person.validators_on(:name, :presence)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the :kind option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Busted.

Fixing now.

This will filter out the validators on a particular attribute based on
its kind.
@sikachu
Copy link
Member Author

sikachu commented Oct 3, 2012

Pull request updated.

@rafaelfranca
Copy link
Member

This will be useful ❤️

rafaelfranca added a commit that referenced this pull request Oct 3, 2012
Make `.validators_on` accept `:kind` option
@rafaelfranca rafaelfranca merged commit 4e9f53f into rails:master Oct 3, 2012
rafaelfranca added a commit that referenced this pull request Oct 3, 2012
This reverts commit 4e9f53f, reversing
changes made to 6b802cd.

Revert "Don't use tap in this case."

This reverts commit 454d820.

Reason: Is not a good idea to add options to this method since we can do
the same thing using method composition.

    Person.validators_on(:name).select { |v| v.kind == :presence }

Also it avoids to change the method again to add more options.
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.

None yet

2 participants