Sha256: abe13ad5ed940596b30a89893d3dc1f311073a0c9c2809c491040d2d13e01acc

Contents?: true

Size: 907 Bytes

Versions: 7

Compression:

Stored size: 907 Bytes

Contents

require 'cliutils/pretty_io'

module CLIUtils
  #  CLIMessenger Module
  #  Outputs coordinated messages to a variety of targets.
  module Messaging
    include PrettyIO

    # Hook that triggers when this module is included.
    # @param [Object] k The includer object
    # @return [void]
    def self.included(k)
      k.extend(self)
    end

    # Returns a default instance of LoggerDelegator that
    # delegates to STDOUT only.
    # @return [LoggerDelegator]
    def default_instance
      stdout_logger = Logger.new(STDOUT)
      stdout_logger.formatter = proc do |severity, datetime, progname, msg|
        send(severity.downcase, msg)
      end

      LoggerDelegator.new(STDOUT: stdout_logger)
    end

    # Singleton method to return (or initialize, if needed)
    # a LoggerDelegator.
    # @return [LoggerDelegator]
    def messenger
      @@messenger ||= default_instance
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cliutils-1.4.2 lib/cliutils/messaging.rb
cliutils-1.4.1 lib/cliutils/messaging.rb
cliutils-1.4.0 lib/cliutils/messaging.rb
cliutils-1.3.1 lib/cliutils/messaging.rb
cliutils-1.3.0 lib/cliutils/messaging.rb
cliutils-1.2.9 lib/cliutils/messaging.rb
cliutils-1.2.8 lib/cliutils/messaging.rb