Module: CouchResource::Validations::InstanceMethods

Defined in:
lib/couch_resource/validations.rb

Instance Method Summary collapse

Instance Method Details

#errorsObject



470
471
472
# File 'lib/couch_resource/validations.rb', line 470

def errors
  @errors ||= Errors.new(self)
end

#save_with_validation(perform_validation = true) ⇒ Object



493
494
495
496
497
498
499
# File 'lib/couch_resource/validations.rb', line 493

def save_with_validation(perform_validation=true)
  if perform_validation && valid? || !perform_validation
    save_without_validation
  else
    false
  end
end

#save_with_validation!Object



501
502
503
504
505
506
507
# File 'lib/couch_resource/validations.rb', line 501

def save_with_validation!
  if valid?
    save_without_validation!
  else
    raise RecordInvalid.new(self)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/couch_resource/validations.rb', line 474

def valid?
  errors.clear

  run_callbacks(:validate)
  validate
  # validate the object only which has #new? method.
  if respond_to?(:new?)
    if new?
      run_callbacks(:validate_on_create)
      validate_on_create
    else
      run_callbacks(:validate_on_update)
      validate_on_update
    end
  end

  errors.empty?
end