Module: KDoc::Guarded

Included in:
Container, Datum
Defined in:
lib/k_doc/mixins/guarded.rb

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

Instance Method Details

#clear_errorsObject



46
47
48
# File 'lib/k_doc/mixins/guarded.rb', line 46

def clear_errors
  errors.clear
end

#error_hashObject



27
28
29
# File 'lib/k_doc/mixins/guarded.rb', line 27

def error_hash
  errors.map(&:to_h)
end

#error_messagesObject



23
24
25
# File 'lib/k_doc/mixins/guarded.rb', line 23

def error_messages
  errors.map(&:message)
end

#errorsObject



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(message, log: false)
  errors << Guard.new(:guard, message)
end

#log_any_messagesObject



39
40
41
42
43
44
# File 'lib/k_doc/mixins/guarded.rb', line 39

def log_any_messages
  errors.each do |error|
    log.warn error.message if error.type == :warning
    log.error error.message if error.type == :guard
  end
end

#valid?Boolean

TODO: Add these predicates def errors? def warnings?

Returns:

  • (Boolean)


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(message)
  errors << Guard.new(:warning, message)
end