Module: ErrorChecks
Instance Method Summary collapse
- #check_error(exception, *args, &block) ⇒ Object
- #check_integer(num) ⇒ Object
- #check_nonempty_string(str) ⇒ Object
- #check_view_parameter(view) ⇒ Object
- #confirm(exception, *args, &block) ⇒ Object
Instance Method Details
#check_error(exception, *args, &block) ⇒ Object
40 41 42 43 |
# File 'lib/runeblog.rb', line 40 def check_error(exception, *args, &block) # raise if block IS true raise send(exception.to_s, *args) if block.call end |
#check_integer(num) ⇒ Object
31 32 33 |
# File 'lib/runeblog.rb', line 31 def check_integer(num) confirm(ExpectedInteger, num, num.class) { num.is_a? Integer } end |
#check_nonempty_string(str) ⇒ Object
23 24 25 |
# File 'lib/runeblog.rb', line 23 def check_nonempty_string(str) confirm(ExpectedString, str.inspect, str.class) { str.is_a?(String) && ! str.empty? } end |
#check_view_parameter(view) ⇒ Object
27 28 29 |
# File 'lib/runeblog.rb', line 27 def check_view_parameter(view) confirm(ExpectedView, view, view.class) { view.is_a?(String) || view.is_a?(RuneBlog::View) } end |
#confirm(exception, *args, &block) ⇒ Object
35 36 37 38 |
# File 'lib/runeblog.rb', line 35 def confirm(exception, *args, &block) # raise if block is NOT true raise send(exception.to_s, *args) if ! block.call end |