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



41
42
43
44
# File 'lib/irb/notifier.rb', line 41

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.



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

def prefix
  @prefix
end

Instance Method Details

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

Execute the given block if notifications are enabled.

Yields:

  • (@base_notifier)


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

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)


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

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.



82
83
84
85
86
# File 'lib/irb/notifier.rb', line 82

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.



92
93
94
95
96
# File 'lib/irb/notifier.rb', line 92

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

See OutputMethod#print for more detail.



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

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

#printf(format, *opts) ⇒ Object

See OutputMethod#printf for more detail.



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

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

#printn(*opts) ⇒ Object

See OutputMethod#printn for more detail.



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

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

#puts(*objs) ⇒ Object

See OutputMethod#puts for more detail.



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

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