lib/validatable_class_methods.rb in validatable-1.3.4 vs lib/validatable_class_methods.rb in validatable-1.4.0
- old
+ new
@@ -193,15 +193,19 @@
# * if - A block that when executed must return true of the validation will not occur.
def include_validations_for(attribute_to_validate, options = {})
children_to_validate << ChildValidation.new(attribute_to_validate, options[:map] || {}, options[:if] || lambda { true })
end
- def validate_children(instance, groups) #:nodoc:
+ def validate_children(instance, group) #:nodoc:
self.children_to_validate.each do |child_validation|
next unless child_validation.should_validate?(instance)
child = instance.send child_validation.attribute
- child.valid?(*groups)
+ if (child.respond_to?(:valid_for_group?))
+ child.valid_for_group?(group)
+ else
+ child.valid?
+ end
child.errors.each do |attribute, messages|
if messages.is_a?(String)
add_error(instance, child_validation.map[attribute.to_sym] || attribute, messages)
else
messages.each do |message|
@@ -218,15 +222,19 @@
def add_error(instance, attribute, msg) #:nodoc:
instance.errors.add(attribute, msg)
end
+ def validation_keys_include?(key)
+ validations.map { |validation| validation.key }.include?(key)
+ end
+
protected
def add_validations(args, klass) #:nodoc:
options = args.last.is_a?(Hash) ? args.pop : {}
args.each do |attribute|
- new_validation = klass.new attribute, options
+ new_validation = klass.new self, attribute, options
self.validations << new_validation
self.create_valid_method_for_groups new_validation.groups
end
end
\ No newline at end of file