module Mixture::Extensions::Validatable::InstanceMethods

The instance methods.

Public Instance Methods

errors() click to toggle source

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

@return [Hash{Attribute => Array<ValidationError>}]

# File lib/mixture/extensions/validatable.rb, line 53
def errors
  @errors ||= Hash.new { |h, k| h[k] = [] }
end
invalid?() click to toggle source

Opposite of valid.

@see valid? @return [Boolean]

# File lib/mixture/extensions/validatable.rb, line 45
def invalid?
  !valid?
end
valid?() click to toggle source

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

@return [Boolean]

# 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