Sha256: ca327dbfaefa178b598ed66708892027ea10676f4f4d6765edce176e60e261a0
Contents?: true
Size: 963 Bytes
Versions: 29
Compression:
Stored size: 963 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_model_callbacks :validation define_callbacks :validate, scope: :name end module ClassMethods def create!(attributes = {}) new(attributes).tap do |object| object.save! end end end def valid? run_callbacks :validation do super 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
29 entries across 29 versions & 1 rubygems