Module: Mixture::Validate
- Defined in:
- lib/mixture/validate.rb,
lib/mixture/validate/base.rb,
lib/mixture/validate/match.rb,
lib/mixture/validate/presence.rb
Defined Under Namespace
Classes: Base, Match, Presence
Class Method Summary
collapse
Class Method Details
.register(name, validator) ⇒ Object
5
6
7
|
# File 'lib/mixture/validate.rb', line 5
def self.register(name, validator)
validations[name] = validator
end
|
.validate(record, attribute, value) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/mixture/validate.rb', line 21
def self.validate(record, attribute, value)
attribute.options[:validate].each do |k, v|
validator = validations.fetch(k).new(v)
validate_with(validator, record, attribute, value)
end
end
|
.validate_with(validator, record, attribute, value) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/mixture/validate.rb', line 28
def self.validate_with(validator, record, attribute, value)
validator.validate(record, attribute, value)
rescue ValidationError => e
record.errors[attribute] << e
end
|
.validations ⇒ Object
9
10
11
|
# File 'lib/mixture/validate.rb', line 9
def self.validations
@_validations ||= {}
end
|