Sha256: eff8b8894e8ae082e1da2df268999c03f9733ac5f02d4f97b8ead0b058c01941
Contents?: true
Size: 1.65 KB
Versions: 20
Compression:
Stored size: 1.65 KB
Contents
module WhyValidationsSuckIn96 # A mixin to handle specifying :if and :unless options to check before performing validation. # # @example Validate if a given block returns true # setup_validations do # validates_associated :tracks, :if => lambda { !validatable.tracks.empty? } # end # # @example Validate if a given method on the validatable object returns true # setup_validations do # validates_associated :tracks, :if => :allow_validation # end # # def allow_validation # false # end # # @example Validate unless a given block returns true # setup_validations do # validates_associated :tracks, :unless => lambda { validatable.tracks.empty? } # end # # @example Validate unless a given method on the validatable object returns true # setup_validations do # validates_associated :tracks, :unless => :disallow_validation # end # # def disallow_validation # true # end module SkippableValidation def validate skip if skip_validation? end private def skip throw :validation_done, nil end def skip_validation? skip_if? || skip_unless? end def skip_unless? return false unless options.has_key?(:unless) check = options[:unless].is_a?(Proc) ? instance_eval(&options[:unless]) : validatable.send(options[:unless]) check == true end def skip_if? return false unless options.has_key?(:if) check = options[:if].is_a?(Proc) ? instance_eval(&options[:if]) : validatable.send(options[:if]) check == false end end # SkippableValidation end # WhyValidationsSuckIn96
Version data entries
20 entries across 20 versions & 1 rubygems