Sha256: 5d7c143dc385502645114b6a8a1a93f05291c2574ab7d2156482b28bcb2047ab
Contents?: true
Size: 1.02 KB
Versions: 15
Compression:
Stored size: 1.02 KB
Contents
module AssetCloud module Validations def self.included(base) base.send(:alias_method, :store_without_validation, :store) base.extend(ClassMethods) base.prepend(PrependedMethods) end module PrependedMethods def store validate errors.empty? ? super : false end end module ClassMethods def validate(*extra_validations, &block) validations = self._callbacks[:validate] || [] validations += extra_validations validations << block if block_given? self._callbacks = _callbacks.merge(validate: validations.freeze).freeze end end def errors @errors ||= [] end def warnings @warnings ||= [] end def valid? validate errors.empty? end def add_error(msg) errors << msg errors.uniq! end def add_warning(*msgs) warnings.concat(msgs) end def validate errors.clear warnings.clear execute_callbacks(:validate, []) end end end
Version data entries
15 entries across 15 versions & 1 rubygems