lib/ratatouille/ratifier.rb in ratatouille-0.1.0 vs lib/ratatouille/ratifier.rb in ratatouille-0.9.2

- old
+ new

@@ -14,11 +14,11 @@ case obj when Hash then extend Ratatouille::HashMethods when Array then extend Ratatouille::ArrayMethods end - instance_eval( &block ) if block_given? + instance_eval(&block) if block_given? cleanup_errors @errors.freeze end#initialize @@ -26,17 +26,15 @@ # Add validation error. Useful for custom validations. # @param [String] str # @param [String] context # @return [void] - def validation_error(err_in, context="/") - case err_in - when String - return if err_in.blank? - @errors[context] = [] unless @errors[context] - @errors[context] << err_in - end + def validation_error(str="", context="/") + return unless str.respond_to?(:to_s) + return if str.to_s.chomp == '' + @errors[context] = [] unless @errors[context] + @errors[context] << str.to_s rescue Exception => e @errors["/"] << e.message end#validation_error @@ -50,10 +48,12 @@ # If there are no errors in the errors hash, empty it out. # # @return [void] def cleanup_errors - @errors = {} if errors_array.empty? + if errors_array.empty? + @errors = {} + end rescue Exception => e @errors["/"] << e.message end#cleanup_errors