# # notifier.rb - output methods used by irb # $Release Version: 0.9.6$ # $Revision: 26986 $ # by Keiju ISHITSUKA(keiju@ruby-lang.org) # # -- # # # require "e2mmap" require "irb/output-method" module IRB module Notifier extend Exception2MessageMapper def_exception :ErrUndefinedNotifier, "undefined notifier level: %d is specified" def_exception :ErrUnrecognizedLevel, "unrecognized notifier level: %s is specified" def def_notifier(prefix = "", output_method = StdioOutputMethod.new) CompositeNotifier.new(prefix, output_method) end module_function :def_notifier class AbstractNotifier def initialize(prefix, base_notifier) @prefix = prefix @base_notifier = base_notifier end attr_reader :prefix def notify? true end def print(*opts) @base_notifier.print prefix, *opts if notify? end def printn(*opts) @base_notifier.printn prefix, *opts if notify? end def printf(format, *opts) @base_notifier.printf(prefix + format, *opts) if notify? end def puts(*objs) if notify? @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s}) end end def pp(*objs) if notify? @base_notifier.ppx @prefix, *objs end end def ppx(prefix, *objs) if notify? @base_notifier.ppx @prefix+prefix, *objs end end def exec_if yield(@base_notifier) if notify? end end class CompositeNotifier(other) @level <=> other.level end def notify? @base_notifier.level >= self end end class NoMsgNotifier