Sha256: ed2a022d8c378c413780d815965bbceb01dad64d250071c395cc360cd589775e
Contents?: true
Size: 839 Bytes
Versions: 19
Compression:
Stored size: 839 Bytes
Contents
module CassandraObject class RecordInvalid < StandardError attr_reader :record def initialize(record) @record = record super("Invalid record: #{@record.errors.full_messages.to_sentence}") end end module Validations extend ActiveSupport::Concern include ActiveModel::Validations included do define_callbacks :validate, scope: :name end module ClassMethods def create!(attributes = {}) new(attributes).tap do |object| object.save! end end end def save(options={}) perform_validations(options) ? super : false end def save! save || raise(RecordInvalid.new(self)) end protected def perform_validations(options={}) (options[:validate] != false) ? valid? : true end end end
Version data entries
19 entries across 19 versions & 1 rubygems