Sha256: 66b126404f618b5fad7a141e95b1652a95fa053b947e2dc98b485fcedec2a277
Contents?: true
Size: 887 Bytes
Versions: 21
Compression:
Stored size: 887 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={}) if perform_validations(options) super true else false end 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
21 entries across 21 versions & 1 rubygems