Module: KDoc::Guarded
Overview
Guarded provides parameter warning and guarding
TODO: this could be moved into KType or KGuard
Defined Under Namespace
Classes: Guard
Instance Method Summary collapse
- #clear_errors ⇒ Object
- #error_hash ⇒ Object
- #error_messages ⇒ Object
- #errors ⇒ Object
- #guard(message, log: false) ⇒ Object
- #log_any_messages ⇒ Object
-
#valid? ⇒ Boolean
TODO: Add these predicates def errors? def warnings?.
- #warn(message) ⇒ Object (also: #warning)
Instance Method Details
#clear_errors ⇒ Object
46 47 48 |
# File 'lib/k_doc/mixins/guarded.rb', line 46 def clear_errors errors.clear end |
#error_hash ⇒ Object
27 28 29 |
# File 'lib/k_doc/mixins/guarded.rb', line 27 def error_hash errors.map(&:to_h) end |
#error_messages ⇒ Object
23 24 25 |
# File 'lib/k_doc/mixins/guarded.rb', line 23 def errors.map(&:message) end |
#errors ⇒ Object
19 20 21 |
# File 'lib/k_doc/mixins/guarded.rb', line 19 def errors @errors ||= [] end |
#guard(message, log: false) ⇒ Object
10 11 12 |
# File 'lib/k_doc/mixins/guarded.rb', line 10 def guard(, log: false) errors << Guard.new(:guard, ) end |
#log_any_messages ⇒ Object
39 40 41 42 43 44 |
# File 'lib/k_doc/mixins/guarded.rb', line 39 def errors.each do |error| log.warn error. if error.type == :warning log.error error. if error.type == :guard end end |
#valid? ⇒ Boolean
TODO: Add these predicates def errors? def warnings?
35 36 37 |
# File 'lib/k_doc/mixins/guarded.rb', line 35 def valid? errors.length.zero? end |
#warn(message) ⇒ Object Also known as: warning
14 15 16 |
# File 'lib/k_doc/mixins/guarded.rb', line 14 def warn() errors << Guard.new(:warning, ) end |