Module: Cequel::Record::Validations
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cequel/record/validations.rb
Overview
Cequel::Record classes can define validations that are run before saving a record instance.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #save(options = {}) ⇒ Object
-
#save!(attributes = {}) ⇒ Record
Attempt to save the record, or raise an exception if there is a validation error.
-
#update_attributes!(attributes) ⇒ Record
Set the given attributes and attempt to save, raising an exception if there is a validation error.
Instance Method Details
#save(options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/cequel/record/validations.rb', line 50 def save( = {}) validate = .fetch(:validate, true) .delete(:validate) (!validate || valid?) && super end |
#save!(attributes = {}) ⇒ Record
Attempt to save the record, or raise an exception if there is a validation error
64 65 66 67 68 69 70 |
# File 'lib/cequel/record/validations.rb', line 64 def save!(attributes = {}) tap do unless save(attributes) fail RecordInvalid, errors..join("; ") end end end |
#update_attributes!(attributes) ⇒ Record
Set the given attributes and attempt to save, raising an exception if there is a validation error
79 80 81 82 |
# File 'lib/cequel/record/validations.rb', line 79 def update_attributes!(attributes) self.attributes = attributes save! end |