Module: Mixture::Extensions::Validatable::InstanceMethods

Defined in:
lib/mixture/extensions/validatable.rb

Overview

The instance methods.

Instance Method Summary collapse

Instance Method Details

#errorsObject



34
35
36
# File 'lib/mixture/extensions/validatable.rb', line 34

def errors
  @errors ||= Hash.new { |h, k| h[k] = [] }
end

#invalid?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mixture/extensions/validatable.rb', line 30

def invalid?
  !valid?
end

#valid?Boolean

Validates the attributes on the record.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/mixture/extensions/validatable.rb', line 21

def valid?
  @errors = Hash.new { |h, k| h[k] = [] }
  self.class.attributes.each do |name, attribute|
    next unless attribute.options[:validate]
    Validate.validate(self, attribute, attribute(name))
  end
  !@errors.values.any?(&:any?)
end