Class: IRB::Notifier::AbstractNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/irb/notifier.rb

Overview

An abstract class, or superclass, for CompositeNotifier and LeveledNotifier to inherit. It provides several wrapper methods for the OutputMethod object used by the Notifier.

Direct Known Subclasses

CompositeNotifier, LeveledNotifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, base_notifier) ⇒ AbstractNotifier

Creates a new Notifier object



47
48
49
50
# File 'lib/irb/notifier.rb', line 47

def initialize(prefix, base_notifier)
  @prefix = prefix
  @base_notifier = base_notifier
end

Instance Attribute Details

#prefixObject (readonly)

The prefix for this Notifier, which is appended to all objects being inspected during output.



54
55
56
# File 'lib/irb/notifier.rb', line 54

def prefix
  @prefix
end

Instance Method Details

#exec_if {|@base_notifier| ... } ⇒ Object

Execute the given block if notifications are enabled.

Yields:

  • (@base_notifier)


105
106
107
# File 'lib/irb/notifier.rb', line 105

def exec_if
  yield(@base_notifier) if notify?
end

#notify?Boolean

A wrapper method used to determine whether notifications are enabled.

Defaults to true.

Returns:

  • (Boolean)


59
60
61
# File 'lib/irb/notifier.rb', line 59

def notify?
  true
end

#pp(*objs) ⇒ Object

Same as #ppx, except it uses the #prefix given during object initialization. See OutputMethod#ppx for more detail.



88
89
90
91
92
# File 'lib/irb/notifier.rb', line 88

def pp(*objs)
  if notify?
    @base_notifier.ppx @prefix, *objs
  end
end

#ppx(prefix, *objs) ⇒ Object

Same as #pp, except it concatenates the given prefix with the #prefix given during object initialization.

See OutputMethod#ppx for more detail.



98
99
100
101
102
# File 'lib/irb/notifier.rb', line 98

def ppx(prefix, *objs)
  if notify?
    @base_notifier.ppx @prefix+prefix, *objs
  end
end

See OutputMethod#print for more detail.



64
65
66
# File 'lib/irb/notifier.rb', line 64

def print(*opts)
  @base_notifier.print prefix, *opts if notify?
end

#printf(format, *opts) ⇒ Object

See OutputMethod#printf for more detail.



74
75
76
# File 'lib/irb/notifier.rb', line 74

def printf(format, *opts)
  @base_notifier.printf(prefix + format, *opts) if notify?
end

#printn(*opts) ⇒ Object

See OutputMethod#printn for more detail.



69
70
71
# File 'lib/irb/notifier.rb', line 69

def printn(*opts)
  @base_notifier.printn prefix, *opts if notify?
end

#puts(*objs) ⇒ Object

See OutputMethod#puts for more detail.



79
80
81
82
83
# File 'lib/irb/notifier.rb', line 79

def puts(*objs)
  if notify?
    @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
  end
end