Module: Simplecheck
- Defined in:
- lib/simplecheck.rb,
lib/simplecheck/version.rb,
lib/simplecheck/check_failed.rb
Defined Under Namespace
Classes: CheckFailed
Constant Summary collapse
- VERSION =
'2.0'
Class Method Summary collapse
- .check_arguments(arguments) ⇒ Object
- .check_arguments_with_block(arguments, block) ⇒ Object
- .check_case_equality(*arguments, check_argument) ⇒ Object
- .check_expression(expression_satisfied) ⇒ Object
- .handle_failure(message) ⇒ Object
Instance Method Summary collapse
Class Method Details
.check_arguments(arguments) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/simplecheck.rb', line 15 def self.check_arguments(arguments) case arguments.size when 1 check_expression(arguments[0]) else check_case_equality(*arguments) end end |
.check_arguments_with_block(arguments, block) ⇒ Object
24 25 26 |
# File 'lib/simplecheck.rb', line 24 def self.check_arguments_with_block(arguments, block) check_arguments(arguments + [block]) end |
.check_case_equality(*arguments, check_argument) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/simplecheck.rb', line 32 def self.check_case_equality(*arguments, check_argument) invalid_argument_index = arguments.index{ |argument| !(check_argument === argument) } if invalid_argument_index "#{ arguments[invalid_argument_index] } does not satisfy #{ check_argument }" end end |
.check_expression(expression_satisfied) ⇒ Object
28 29 30 |
# File 'lib/simplecheck.rb', line 28 def self.check_expression(expression_satisfied) 'Condition is not satisfied' unless expression_satisfied end |
.handle_failure(message) ⇒ Object
40 41 42 |
# File 'lib/simplecheck.rb', line 40 def self.handle_failure() fail(Simplecheck::CheckFailed, ) end |
Instance Method Details
#check(*arguments, error_message: nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/simplecheck.rb', line 5 def check(*arguments, error_message: nil, &block) = if block_given? Simplecheck.check_arguments_with_block(arguments, block) else Simplecheck.check_arguments(arguments) end ? Simplecheck.handle_failure( || ) : true end |