lib/cliutils/messenger.rb in cliutils-2.2.0 vs lib/cliutils/messenger.rb in cliutils-2.2.1
- old
+ new
@@ -1,9 +1,11 @@
require 'cliutils/pretty_io'
require 'readline'
module CLIUtils
+ # Allows for messages to be sent to STDOUT, as well
+ # as any number of Logger instances.
class Messenger
include PrettyIO
# The endpoints to which delegation occurs.
# @return [Array]
@@ -15,12 +17,12 @@
def attach(target)
fail "Cannot add invalid target: #{ target }" unless target.is_a?(Hash)
@targets.merge!(target)
end
- # Empty method so that Messaging doesn't freak out when passed a debug
- # message.
+ # Outputs a debug message; since this shouldn't appear in STDOUT,
+ # only send it to the Logger targets.
# @return [void]
def debug(m)
@targets.each { |_, t| t.debug(m) }
end
@@ -48,13 +50,20 @@
def info(m)
puts _word_wrap(m, '# ').blue
@targets.each { |_, t| t.info(m) }
end
+ # Deprecated method to show info messages around
+ # a block of actions
+ # @param [Array] params
+ # @return [void]
def info_block(*params)
warn('As of 2.2.0, `info_block` is deprecated and nonfunctioning.')
end
+ # Initializes a new Messenger with an optional
+ # Hash of targets.
+ # @param [Hash] targets Logger targets
def initialize(targets = {})
@targets = targets
end
# Outputs a prompt, collects the user's response, and