Class: SettingAccessors::Validator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/setting_accessors/validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/setting_accessors/validator.rb', line 3

def validate(record)
  record.send(:validations).each do |key, requirement|
    if key.to_s == 'custom'
      Array(requirement).each do |validation|
        run_custom_validation(record, validation)
      end
    elsif built_in_validation?(key)
      send("validate_#{key}", record, requirement)
    else
      raise ArgumentError.new("The invalid validation '#{key}' was given in model '#{defining_model(record).to_s}'")
    end
  end
end