123456789_123456789_123456789_123456789_123456789_

Class: IRB::Notifier::CompositeNotifier

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: IRB::Notifier::AbstractNotifier
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 def_notifier to create a new composite notifier. Using the first composite notifier object you create, sibling notifiers can be initialized with #def_notifier.

Class Method Summary

AbstractNotifier - Inherited

.new

Creates a new ::IRB::Notifier object.

Instance Attribute Summary

AbstractNotifier - Inherited

#notify?

A wrapper method used to determine whether notifications are enabled.

#prefix

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

Instance Method Summary

AbstractNotifier - Inherited

#exec_if

Execute the given block if notifications are enabled.

#pp

Same as #ppx, except it uses the #prefix given during object initialization.

#ppx

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

#print

See OutputMethod#print for more detail.

#printf

See OutputMethod#printf for more detail.

#printn

See OutputMethod#printn for more detail.

#puts

See OutputMethod#puts for more detail.

Constructor Details

.new(prefix, base_notifier) ⇒ CompositeNotifier

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

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 118

def initialize(prefix, base_notifier)
  super

  @notifiers = [D_NOMSG]
  @level_notifier = D_NOMSG
end

Instance Attribute Details

#level (rw)

Alias for #level_notifier.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 142

alias level level_notifier

#level_notifier (rw) Also known as: #level

Returns the leveled notifier for this object

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 141

attr_reader :level_notifier

#level_notifier=(value) (rw) Also known as: #level=

Sets the leveled notifier for this object.

When the given value is an instance of AbstractNotifier, #level_notifier is set to the given object.

When an Integer is given, #level_notifier is set to the notifier at the index value in the #notifiers Array.

If no notifier exists at the index value in the #notifiers Array, an ErrUndefinedNotifier exception is raised.

An ErrUnrecognizedLevel exception is raised if the given value is not found in the existing #notifiers Array, or an instance of AbstractNotifier

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 158

def level_notifier=(value)
  case value
  when AbstractNotifier
    @level_notifier = value
  when Integer
    l = @notifiers[value]
    Notifier.Raise ErrUndefinedNotifier, value unless l
    @level_notifier = l
  else
    Notifier.Raise ErrUnrecognizedLevel, value unless l
  end
end

#notifiers (readonly)

List of notifiers in the group

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 126

attr_reader :notifiers

Instance Method Details

#def_notifier(level, prefix = "")

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.

[ GitHub ]

  
# File 'lib/irb/notifier.rb', line 134

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