Module: Ripple::Validations

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Validations
Defined in:
lib/ripple/validations.rb,
lib/ripple/validations/associated_validator.rb

Overview

Adds validations to Document models. Validations are executed before saving the document.

Defined Under Namespace

Modules: ClassMethods Classes: AssociatedValidator

Instance Method Summary collapse

Instance Method Details

#save(options = {:validate => true}) ⇒ Object



46
47
48
49
# File 'lib/ripple/validations.rb', line 46

def save(options={:validate => true})
  return false if options[:validate] && !valid?
  super()
end

#save!Object

Saves the document and raises DocumentInvalid exception if validations fail.



53
54
55
# File 'lib/ripple/validations.rb', line 53

def save!
  (raise Ripple::DocumentInvalid.new(self) unless save) || true
end

#update_attributes!(attrs) ⇒ Object

Sets the passed attributes and saves the document, raising a DocumentInvalid exception if the validations fail.



59
60
61
62
# File 'lib/ripple/validations.rb', line 59

def update_attributes!(attrs)
  self.attributes = attrs
  save!
end