Module: Modelish::Validations

Included in:
Base
Defined in:
lib/modelish/validations.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/modelish/validations.rb', line 33

def valid?
  validate.empty?
end

#validateHash<Symbol,Array>

Validates all properties based on configured validators.

Returns:

  • (Hash<Symbol,Array>)

    map of errors where key is the property name and value is the list of errors

See Also:



14
15
16
17
18
19
20
21
22
23
# File 'lib/modelish/validations.rb', line 14

def validate
  errors = {}
 
  call_validators do |name,message|
    errors[name] ||= []
    errors[name] << to_error(message)
  end

  errors
end

#validate!Object

Validates all properties based on configured validators.

Raises:

  • ArgumentError when any property fails validation



28
29
30
31
# File 'lib/modelish/validations.rb', line 28

def validate!
  errors = validate
  raise validate.first[1].first unless validate.empty?
end