Sha256: dfecdfffc8ab5a821a81f4f975233083709cbf962a2352fa299adc5f001b61e6
Contents?: true
Size: 604 Bytes
Versions: 6
Compression:
Stored size: 604 Bytes
Contents
module Toy module Validations extend ActiveSupport::Concern include ActiveModel::Validations included do extend ActiveModel::Callbacks define_model_callbacks :validation end module ClassMethods def create!(attrs={}) new(attrs).tap { |doc| doc.save! } end end def valid? run_callbacks(:validation) { super } end def save(options={}) options.assert_valid_keys(:validate) !options.fetch(:validate, true) || valid? ? super : false end def save! save || raise(RecordInvalid.new(self)) end end end
Version data entries
6 entries across 6 versions & 1 rubygems