lib/ratatouille/ratifier.rb in ratatouille-1.3.2 vs lib/ratatouille/ratifier.rb in ratatouille-1.3.4

- old
+ new

@@ -11,16 +11,22 @@ def initialize(obj, options={}, &block) @errors = { "/" => [] } @ratifiable_object = obj self.name = options[:name] + @is_a ||= options[:is_a] + case obj when Hash then extend Ratatouille::HashMethods when Array then extend Ratatouille::ArrayMethods end - instance_eval( &block ) if block_given? + unless @is_a.nil? + is_a?(@is_a, &block) + else + instance_eval( &block ) if block_given? + end cleanup_errors @errors.freeze end#initialize @@ -172,19 +178,27 @@ # Skip to block evaluation when id.to_s =~ /^is_not_(.*)$/ if @ratifiable_object.respond_to?("#{$1}?") if @ratifiable_object.send("#{$1}?") == true validation_error("is #{$1}") + return end end when id.to_s =~ /^is_(.*)$/ if @ratifiable_object.respond_to?("#{$1}?") if @ratifiable_object.send("#{$1}?") == false validation_error("is not #{$1}") + return end end else - validation_error("#{id} is not supported for the given object (#{@ratifiable_object.class})") + begin + super + return + rescue Exception => e + validation_error("#{id} is not supported for the given object (#{@ratifiable_object.class})") + return e + end end instance_eval(&block) if block_given? return end#method_missing