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

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

Overview

The instance methods.

Instance Method Summary collapse

Instance Method Details

#errorsHash{Attribute => Array<ValidationError>}

Returns a hash, mapping attributes to the errors that they have.

Returns:



53
54
55
# File 'lib/mixture/extensions/validatable.rb', line 53

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

#invalid?Boolean

Opposite of valid.

Returns:

  • (Boolean)

See Also:



45
46
47
# File 'lib/mixture/extensions/validatable.rb', line 45

def invalid?
  !valid?
end

#valid?Boolean

Validates the attributes on the record. This will fill up #errors with errors, if there are any.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/mixture/extensions/validatable.rb', line 32

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