Module: WhyValidationsSuckIn96::ValidationSupport::ClassMethods
- Defined in:
- lib/whyvalidationssuckin96/validation_support.rb
Overview
InstanceMethods
Instance Method Summary collapse
-
#run_with_generic_callbacks? ⇒ true, false
If the class or module has a public ‘run_callbacks’ instance method, we run validations and fire appropriate callbacks.
-
#setup_validations(&definition_block) ⇒ Object
Sets up validations for the class or module this module has been mixed into.
-
#validation_collection ⇒ Array
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.
Instance Method Details
#run_with_generic_callbacks? ⇒ true, false
If the class or module has a public ‘run_callbacks’ instance method, we run validations and fire appropriate callbacks
87 88 89 90 91 92 93 |
# File 'lib/whyvalidationssuckin96/validation_support.rb', line 87 def run_with_generic_callbacks? if defined?(@run_with_generic_callbacks) @run_with_generic_callbacks else @run_with_generic_callbacks = !public_instance_methods.grep(/run_callbacks/).empty? end end |
#setup_validations(&definition_block) ⇒ Object
Sets up validations for the class or module this module has been mixed into
107 108 109 110 111 |
# File 'lib/whyvalidationssuckin96/validation_support.rb', line 107 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 |
#validation_collection ⇒ Array
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.
99 100 101 102 103 104 |
# File 'lib/whyvalidationssuckin96/validation_support.rb', line 99 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 |