Sha256: 23b425c684aea7759911beb1525915ca434419a166b10d04ccb05c5d92674cc5
Contents?: true
Size: 873 Bytes
Versions: 78
Compression:
Stored size: 873 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 module ClassMethods def create!(attributes = {}) new(attributes).tap do |object| object.save! end end end def valid?(context=nil) context ||= (new_record? ? :create : :update) super(context) 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
78 entries across 78 versions & 1 rubygems