Sha256: ad189f8c898bcc178aba9029035f639c127da11d2ba015852d70ffa51d9cf9ec
Contents?: true
Size: 966 Bytes
Versions: 30
Compression:
Stored size: 966 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
30 entries across 30 versions & 2 rubygems