Module: WhyValidationsSuckIn96::ValidationSupport::ClassMethods

Defined in:
lib/whyvalidationssuckin96/validation_support.rb

Overview

ClassMethods

Instance Method Summary

Instance Method Details

- (Object) setup_validations(&definition_block)

Sets up validations for the class or module this module has been mixed into



66
67
68
69
70
# File 'lib/whyvalidationssuckin96/validation_support.rb', line 66

def setup_validations(&definition_block)
  self.validation_collection ||= ancestors.detect{|anc| !anc.validation_collection.nil?}.validation_collection.dup
  builder = ValidationBuilder.new(self, definition_block)
  builder.create_validations!
end

- (Array) validation_collection

An array of arrays, the first element of each being the validation subclass that will be instantiated when validation is performed, the last element being the options the validation will be instantiated with.

Returns:

  • (Array)


58
59
60
61
62
63
# File 'lib/whyvalidationssuckin96/validation_support.rb', line 58

def validation_collection
  @validation_collection ||= begin
    ancestor_with_validations = ancestors[1..-1].detect{|anc| anc.respond_to?(:validation_collection) }
    ancestor_with_validations ? ancestor_with_validations.validation_collection.dup : []
  end
end