Sha256: d46b0e1dbf4f9f03dee7e393c7f1a2880f5111ce8b010a2739f2155357e8140d

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

require 'whyvalidationssuckin96/skippable_validation'
require 'whyvalidationssuckin96/attribute_based_validation'

module WhyValidationsSuckIn96
  
  # Checks the validity of any associated objects, such as an ActiveRecord association.
  #
  # @example Checking the validity of an associated collection of tracks
  #   setup_validations do
  #     validates_associated :tracks
  #   end
  #
  # @example Checking the validity of an associated artist
  #   setup_validations do
  #     validates_associated :artist
  #   end
  class ValidatesAssociated < Validation
    DefaultOptions = {:message => "is invalid"}
    
    include WhyValidationsSuckIn96::SkippableValidation
    include WhyValidationsSuckIn96::AttributeBasedValidation
    
    def validate
      super
      Array(attribute_value).collect do |assoc|
        assoc.valid?
      end.all? ? pass : fail
    end
    
  end # Validation

  ValidationBuilder.register_macro :validates_associated, WhyValidationsSuckIn96::ValidatesAssociated
end   # WhyValidationsSuckIn96

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.4 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.6.3 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.6.2 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.6.1 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.6.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.5 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.4 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.3 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.2 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.1 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.5.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.4.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.3.1 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.3.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.2.3 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.2.2 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.2.1 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.2.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.1.0 lib/whyvalidationssuckin96/macros/validates_associated.rb
whyvalidationssuckin96-1.0.0 lib/whyvalidationssuckin96/macros/validates_associated.rb