Module: ValidateAttributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveModel::Validations, ActiveRecord::Base
- Defined in:
- lib/validate_attributes.rb,
lib/validate_attributes/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Method Summary collapse
Instance Method Details
#validate_attributes(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/validate_attributes.rb', line 8 def validate_attributes( = {}) return valid? if .empty? errors.clear # Clean old validations as we're interested only on those _attributes = extract_attributes() # TODO: Use flat_map only with ruby 1.9 if ActiveModel::VERSION::MAJOR == 3 return validate_attributes_3(_attributes) end result = _attributes.map do |attr| self.class.validators_on(attr).map do |validator| validator.validate_each(self, attr.to_sym, send(attr)) self.errors[attr].empty? end end return result.flatten.all? end |