module Cequel::Record::Validations
{Record} classes can define validations that are run before saving a record instance.
@example Validations
class User include Cequel::Record key :login, :text column :email, :text validates :email, presence: true, format: RFC822::EMAIL end
@see api.rubyonrails.org/classes/ActiveModel/Validations.html
ActiveModel::Validations
@since 0.1.0
Public Instance Methods
save(options = {})
click to toggle source
@private
Calls superclass method
# File lib/cequel/record/validations.rb, line 49 def save(options = {}) validate = options.fetch(:validate, true) options.delete(:validate) (!validate || valid?) && super end
save!(attributes = {})
click to toggle source
Attempt to save the record, or raise an exception if there is a validation error
@param (see Persistence#save
) @return [Record] self @raise [RecordInvalid] if there are validation errors
# File lib/cequel/record/validations.rb, line 63 def save!(attributes = {}) tap do unless save(attributes) fail RecordInvalid, errors.full_messages.join("; ") end end end
update_attributes!(attributes)
click to toggle source
Set
the given attributes and attempt to save, raising an exception if there is a validation error
@param (see Persistence#update_attributes
) @return (see save!
) @raise (see save!
)
# File lib/cequel/record/validations.rb, line 78 def update_attributes!(attributes) self.attributes = attributes save! end