Module: Reins::Model::Validations

Included in:
Base
Defined in:
lib/reins/model/validations.rb

Defined Under Namespace

Modules: ClassMethods Classes: FormatValidator, LengthValidator, PresenceValidator, UniquenessValidator, Validator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/reins/model/validations.rb', line 4

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

Instance Method Details

#errorsObject



45
46
47
# File 'lib/reins/model/validations.rb', line 45

def errors
  @errors ||= Errors.new
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/reins/model/validations.rb', line 37

def valid?
  errors.clear
  run_callbacks(:before_validation) if respond_to?(:run_callbacks)
  self.class.all_validators.each { |v| v.validate(self, errors) }
  run_callbacks(:after_validation) if respond_to?(:run_callbacks)
  errors.empty?
end