Module: WhyValidationsSuckIn96::SkippableValidation

Defined in:
lib/whyvalidationssuckin96/skippable_validation.rb

Overview

A mixin to handle specifying :if and :unless options to check before performing validation.

Examples:

Validate if a given block returns true

  setup_validations do
    validates_associated :tracks, :if => lambda { !validatable.tracks.empty? }
  end

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

Validate unless a given block returns true

  setup_validations do
    validates_associated :tracks, :unless => lambda { validatable.tracks.empty? }
  end

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

Instance Method Summary

Instance Method Details

- (Object) validate



33
34
35
# File 'lib/whyvalidationssuckin96/skippable_validation.rb', line 33

def validate
  skip if skip_validation?
end