module Veto::Validator
Public Class Methods
included(base)
click to toggle source
# File lib/veto/validator.rb, line 3 def self.included(base) base.extend ClassMethods end
Public Instance Methods
errors()
click to toggle source
# File lib/veto/validator.rb, line 39 def errors @errors ||= ::Veto::Errors.new end
valid?(entity)
click to toggle source
# File lib/veto/validator.rb, line 43 def valid?(entity) validate(entity) errors.empty? end
validate!(entity)
click to toggle source
# File lib/veto/validator.rb, line 48 def validate!(entity) raise(::Veto::InvalidEntity, errors) unless valid?(entity) end
Private Instance Methods
clear_errors()
click to toggle source
# File lib/veto/validator.rb, line 54 def clear_errors @errors = nil end
populate_entity_errors(entity)
click to toggle source
# File lib/veto/validator.rb, line 64 def populate_entity_errors(entity) if entity.respond_to?(:errors=) entity.errors = errors end end
validate(entity)
click to toggle source
# File lib/veto/validator.rb, line 58 def validate(entity) clear_errors self.class.checker.call(CheckContextObject.new(entity, self, errors)) populate_entity_errors(entity) end