class AbstractValidator
Constants
- VALIDATIONS
Attributes
errors[R]
is_valid[R]
model[R]
valid?[R]
Public Class Methods
new(model)
click to toggle source
# File lib/abstract_validator.rb, line 5 def initialize(model) @model = model validate! @is_valid = @errors.length == 0 end
Private Instance Methods
get_values(keys)
click to toggle source
# File lib/abstract_validator.rb, line 19 def get_values(keys) keys.map do |k| @model.send(k) end end
validate!()
click to toggle source
# File lib/abstract_validator.rb, line 11 def validate! raise NotImplementedError.new "You must implement VALIDATIONS hash in your child class" if self.class::VALIDATIONS.size == 0 @errors = [] self.class::VALIDATIONS.each do |validation| values = get_values(validation[:keys]) @errors << validation[:message] unless validation[:method].call(*values) end end