lib/simplecheck.rb in simplecheck-0.9 vs lib/simplecheck.rb in simplecheck-1.0rc1

- old
+ new

@@ -2,57 +2,42 @@ require 'simplecheck/check_failed' module Simplecheck def check( *arguments, &block ) error_message = if block_given? - __check_arguments_with_block( arguments, block ) + Simplecheck.check_arguments_with_block( arguments, block ) else - __check_arguments( arguments ) + Simplecheck.check_arguments( arguments ) end - if error_message - __handle_failure( error_message ) - else - __handle_return_arguments( arguments ) - end + error_message ? Simplecheck.handle_failure( error_message ) : true end - - private - def __check_arguments( arguments ) + def Simplecheck.check_arguments( arguments ) case arguments.size when 1 - __check_expression( arguments[ 0 ]) + Simplecheck.check_expression( arguments[ 0 ]) else - __check_case_equality( *arguments ) + Simplecheck.check_case_equality( *arguments ) end end - def __check_arguments_with_block( arguments, block ) - __check_arguments(( arguments + [ block ])) + def Simplecheck.check_arguments_with_block( arguments, block ) + Simplecheck.check_arguments(( arguments + [ block ])) end - def __check_expression( expression ) + def Simplecheck.check_expression( expression ) if !expression - 'Condition is not true' + 'Condition is not satisfied' end end - def __check_case_equality( *arguments, receiver ) - if invalid_argument = arguments.find{ |argument| !( receiver === argument )} - "#{ invalid_argument } does not satisfy #{ receiver }" + def Simplecheck.check_case_equality( *arguments, check_argument ) + if invalid_argument = arguments.find{ |argument| !( check_argument === argument )} + "#{ invalid_argument } does not satisfy #{ check_argument }" end end - def __handle_failure( message ) + def Simplecheck.handle_failure( message ) raise Simplecheck::CheckFailed.new( message ) - end - - def __handle_return_arguments( arguments ) - case arguments.size - when 1 - arguments[0] - else - arguments - end end end