Module: Validatable::ClassMethods
- Defined in:
- lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb
Overview
:nodoc:
Instance Method Summary collapse
- #add_error(instance, attribute, msg) ⇒ Object
- #all_before_validations ⇒ Object
- #all_validations ⇒ Object
- #before_validations ⇒ Object
- #validate_children(instance, group) ⇒ Object
- #validation_keys_include?(key) ⇒ Boolean
- #validations ⇒ Object
- #validations_to_include ⇒ Object
Instance Method Details
#add_error(instance, attribute, msg) ⇒ Object
47 48 49 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 47 def add_error(instance, attribute, msg) instance.errors.add(attribute, msg) end |
#all_before_validations ⇒ Object
25 26 27 28 29 30 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 25 def all_before_validations if self.superclass.respond_to? :all_before_validations return before_validations + self.superclass.all_before_validations end before_validations end |
#all_validations ⇒ Object
36 37 38 39 40 41 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 36 def all_validations if self.respond_to?(:superclass) && self.superclass.respond_to?(:all_validations) return validations + self.superclass.all_validations end validations end |
#before_validations ⇒ Object
32 33 34 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 32 def before_validations @before_validations ||= [] end |
#validate_children(instance, group) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 4 def validate_children(instance, group) self.children_to_validate.each do |child_validation| next unless child_validation.should_validate?(instance) child = instance.send child_validation.attribute if (child.respond_to?(:valid_for_group?)) child.valid_for_group?(group) else child.valid? end child.errors.each do |attribute, | if .is_a?(String) add_error(instance, child_validation.map[attribute.to_sym] || attribute, ) else .each do || add_error(instance, child_validation.map[attribute.to_sym] || attribute, ) end end end end end |
#validation_keys_include?(key) ⇒ Boolean
51 52 53 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 51 def validation_keys_include?(key) validations.map { |validation| validation.key }.include?(key) end |
#validations ⇒ Object
43 44 45 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 43 def validations @validations ||= [] end |
#validations_to_include ⇒ Object
55 56 57 |
# File 'lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb', line 55 def validations_to_include @validations_to_include ||= [] end |