Sha256: 1972fd3958842fce05b208e28af102437acb8a0b20310f04fdbc3a1b882ed9f9
Contents?: true
Size: 562 Bytes
Versions: 3
Compression:
Stored size: 562 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.fetch(:validate, true) || valid? ? super : false end def save! save || raise(RecordInvalid.new(self)) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
toystore-0.13.2 | lib/toy/validations.rb |
toystore-0.13.1 | lib/toy/validations.rb |
toystore-0.13.0 | lib/toy/validations.rb |