Class: IRB::Notifier::CompositeNotifier

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

Overview

A class that can be used to create a group of notifier objects with the intent of representing a leveled notification system for irb.

This class will allow you to generate other notifiers, and assign them the appropriate level for output.

The Notifier class provides a class-method Notifier.def_notifier to create a new composite notifier. Using the first composite notifier object you create, sibling notifiers can be initialized with #def_notifier.

Instance Attribute Summary collapse

Attributes inherited from AbstractNotifier

#prefix

Instance Method Summary collapse

Methods inherited from AbstractNotifier

#exec_if, #notify?, #pp, #ppx, #print, #printf, #printn, #puts

Constructor Details

#initialize(prefix, base_notifier) ⇒ CompositeNotifier

Create a new composite notifier object with the given prefix, and base_notifier to use for output.



123
124
125
126
127
128
# File 'lib/irb/notifier.rb', line 123

def initialize(prefix, base_notifier)
  super

  @notifiers = [D_NOMSG]
  @level_notifier = D_NOMSG
end

Instance Attribute Details

#level_notifierObject Also known as: level

Returns the leveled notifier for this object



146
147
148
# File 'lib/irb/notifier.rb', line 146

def level_notifier
  @level_notifier
end

#notifiersObject (readonly)

List of notifiers in the group



131
132
133
# File 'lib/irb/notifier.rb', line 131

def notifiers
  @notifiers
end

Instance Method Details

#def_notifier(level, prefix = "") ⇒ Object

Creates a new LeveledNotifier in the composite #notifiers group.

The given prefix will be assigned to the notifier, and level will be used as the index of the #notifiers Array.

This method returns the newly created instance.



139
140
141
142
143
# File 'lib/irb/notifier.rb', line 139

def def_notifier(level, prefix = "")
  notifier = LeveledNotifier.new(self, level, prefix)
  @notifiers[level] = notifier
  notifier
end