Sha256: 23ef799c7466e7b62654b1944d97026ac05d6e2dc80d455af198cd902f8224bb
Contents?: true
Size: 870 Bytes
Versions: 31
Compression:
Stored size: 870 Bytes
Contents
module Superstore 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
31 entries across 31 versions & 1 rubygems