Module: Veto::Validator

Defined in:
lib/veto/validator.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/veto/validator.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#errorsObject



39
40
41
# File 'lib/veto/validator.rb', line 39

def errors
  @errors ||= ::Veto::Errors.new
end

#valid?(entity) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/veto/validator.rb', line 43

def valid?(entity)
  validate(entity)
  errors.empty?
end

#validate!(entity) ⇒ Object



48
49
50
# File 'lib/veto/validator.rb', line 48

def validate!(entity)
  raise(::Veto::InvalidEntity, errors) unless valid?(entity)
end