Module: Mixture::Extensions::Validatable::InstanceMethods
- Defined in:
- lib/mixture/extensions/validatable.rb
Overview
The instance methods.
Instance Method Summary collapse
-
#errors ⇒ Hash{Attribute => Array<ValidationError>}
Returns a hash, mapping attributes to the errors that they have.
-
#invalid? ⇒ Boolean
Opposite of valid.
-
#valid? ⇒ Boolean
Validates the attributes on the record.
Instance Method Details
#errors ⇒ Hash{Attribute => Array<ValidationError>}
Returns a hash, mapping attributes to the errors that they have.
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.
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.
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.[:validate] Validate.validate(self, attribute, attribute(name)) end !@errors.values.any?(&:any?) end |