Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: notifier.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# notifier.rb - output methods used by irb
[2] Fix | Delete
# $Release Version: 0.9.6$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
[11] Fix | Delete
require_relative "output-method"
[12] Fix | Delete
[13] Fix | Delete
module IRB
[14] Fix | Delete
# An output formatter used internally by the lexer.
[15] Fix | Delete
module Notifier
[16] Fix | Delete
class ErrUndefinedNotifier < StandardError
[17] Fix | Delete
def initialize(val)
[18] Fix | Delete
super("undefined notifier level: #{val} is specified")
[19] Fix | Delete
end
[20] Fix | Delete
end
[21] Fix | Delete
class ErrUnrecognizedLevel < StandardError
[22] Fix | Delete
def initialize(val)
[23] Fix | Delete
super("unrecognized notifier level: #{val} is specified")
[24] Fix | Delete
end
[25] Fix | Delete
end
[26] Fix | Delete
[27] Fix | Delete
# Define a new Notifier output source, returning a new CompositeNotifier
[28] Fix | Delete
# with the given +prefix+ and +output_method+.
[29] Fix | Delete
#
[30] Fix | Delete
# The optional +prefix+ will be appended to all objects being inspected
[31] Fix | Delete
# during output, using the given +output_method+ as the output source. If
[32] Fix | Delete
# no +output_method+ is given, StdioOutputMethod will be used, and all
[33] Fix | Delete
# expressions will be sent directly to STDOUT without any additional
[34] Fix | Delete
# formatting.
[35] Fix | Delete
def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
[36] Fix | Delete
CompositeNotifier.new(prefix, output_method)
[37] Fix | Delete
end
[38] Fix | Delete
module_function :def_notifier
[39] Fix | Delete
[40] Fix | Delete
# An abstract class, or superclass, for CompositeNotifier and
[41] Fix | Delete
# LeveledNotifier to inherit. It provides several wrapper methods for the
[42] Fix | Delete
# OutputMethod object used by the Notifier.
[43] Fix | Delete
class AbstractNotifier
[44] Fix | Delete
# Creates a new Notifier object
[45] Fix | Delete
def initialize(prefix, base_notifier)
[46] Fix | Delete
@prefix = prefix
[47] Fix | Delete
@base_notifier = base_notifier
[48] Fix | Delete
end
[49] Fix | Delete
[50] Fix | Delete
# The +prefix+ for this Notifier, which is appended to all objects being
[51] Fix | Delete
# inspected during output.
[52] Fix | Delete
attr_reader :prefix
[53] Fix | Delete
[54] Fix | Delete
# A wrapper method used to determine whether notifications are enabled.
[55] Fix | Delete
#
[56] Fix | Delete
# Defaults to +true+.
[57] Fix | Delete
def notify?
[58] Fix | Delete
true
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
# See OutputMethod#print for more detail.
[62] Fix | Delete
def print(*opts)
[63] Fix | Delete
@base_notifier.print prefix, *opts if notify?
[64] Fix | Delete
end
[65] Fix | Delete
[66] Fix | Delete
# See OutputMethod#printn for more detail.
[67] Fix | Delete
def printn(*opts)
[68] Fix | Delete
@base_notifier.printn prefix, *opts if notify?
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
# See OutputMethod#printf for more detail.
[72] Fix | Delete
def printf(format, *opts)
[73] Fix | Delete
@base_notifier.printf(prefix + format, *opts) if notify?
[74] Fix | Delete
end
[75] Fix | Delete
[76] Fix | Delete
# See OutputMethod#puts for more detail.
[77] Fix | Delete
def puts(*objs)
[78] Fix | Delete
if notify?
[79] Fix | Delete
@base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
[80] Fix | Delete
end
[81] Fix | Delete
end
[82] Fix | Delete
[83] Fix | Delete
# Same as #ppx, except it uses the #prefix given during object
[84] Fix | Delete
# initialization.
[85] Fix | Delete
# See OutputMethod#ppx for more detail.
[86] Fix | Delete
def pp(*objs)
[87] Fix | Delete
if notify?
[88] Fix | Delete
@base_notifier.ppx @prefix, *objs
[89] Fix | Delete
end
[90] Fix | Delete
end
[91] Fix | Delete
[92] Fix | Delete
# Same as #pp, except it concatenates the given +prefix+ with the #prefix
[93] Fix | Delete
# given during object initialization.
[94] Fix | Delete
#
[95] Fix | Delete
# See OutputMethod#ppx for more detail.
[96] Fix | Delete
def ppx(prefix, *objs)
[97] Fix | Delete
if notify?
[98] Fix | Delete
@base_notifier.ppx @prefix+prefix, *objs
[99] Fix | Delete
end
[100] Fix | Delete
end
[101] Fix | Delete
[102] Fix | Delete
# Execute the given block if notifications are enabled.
[103] Fix | Delete
def exec_if
[104] Fix | Delete
yield(@base_notifier) if notify?
[105] Fix | Delete
end
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
# A class that can be used to create a group of notifier objects with the
[109] Fix | Delete
# intent of representing a leveled notification system for irb.
[110] Fix | Delete
#
[111] Fix | Delete
# This class will allow you to generate other notifiers, and assign them
[112] Fix | Delete
# the appropriate level for output.
[113] Fix | Delete
#
[114] Fix | Delete
# The Notifier class provides a class-method Notifier.def_notifier to
[115] Fix | Delete
# create a new composite notifier. Using the first composite notifier
[116] Fix | Delete
# object you create, sibling notifiers can be initialized with
[117] Fix | Delete
# #def_notifier.
[118] Fix | Delete
class CompositeNotifier < AbstractNotifier
[119] Fix | Delete
# Create a new composite notifier object with the given +prefix+, and
[120] Fix | Delete
# +base_notifier+ to use for output.
[121] Fix | Delete
def initialize(prefix, base_notifier)
[122] Fix | Delete
super
[123] Fix | Delete
[124] Fix | Delete
@notifiers = [D_NOMSG]
[125] Fix | Delete
@level_notifier = D_NOMSG
[126] Fix | Delete
end
[127] Fix | Delete
[128] Fix | Delete
# List of notifiers in the group
[129] Fix | Delete
attr_reader :notifiers
[130] Fix | Delete
[131] Fix | Delete
# Creates a new LeveledNotifier in the composite #notifiers group.
[132] Fix | Delete
#
[133] Fix | Delete
# The given +prefix+ will be assigned to the notifier, and +level+ will
[134] Fix | Delete
# be used as the index of the #notifiers Array.
[135] Fix | Delete
#
[136] Fix | Delete
# This method returns the newly created instance.
[137] Fix | Delete
def def_notifier(level, prefix = "")
[138] Fix | Delete
notifier = LeveledNotifier.new(self, level, prefix)
[139] Fix | Delete
@notifiers[level] = notifier
[140] Fix | Delete
notifier
[141] Fix | Delete
end
[142] Fix | Delete
[143] Fix | Delete
# Returns the leveled notifier for this object
[144] Fix | Delete
attr_reader :level_notifier
[145] Fix | Delete
alias level level_notifier
[146] Fix | Delete
[147] Fix | Delete
# Sets the leveled notifier for this object.
[148] Fix | Delete
#
[149] Fix | Delete
# When the given +value+ is an instance of AbstractNotifier,
[150] Fix | Delete
# #level_notifier is set to the given object.
[151] Fix | Delete
#
[152] Fix | Delete
# When an Integer is given, #level_notifier is set to the notifier at the
[153] Fix | Delete
# index +value+ in the #notifiers Array.
[154] Fix | Delete
#
[155] Fix | Delete
# If no notifier exists at the index +value+ in the #notifiers Array, an
[156] Fix | Delete
# ErrUndefinedNotifier exception is raised.
[157] Fix | Delete
#
[158] Fix | Delete
# An ErrUnrecognizedLevel exception is raised if the given +value+ is not
[159] Fix | Delete
# found in the existing #notifiers Array, or an instance of
[160] Fix | Delete
# AbstractNotifier
[161] Fix | Delete
def level_notifier=(value)
[162] Fix | Delete
case value
[163] Fix | Delete
when AbstractNotifier
[164] Fix | Delete
@level_notifier = value
[165] Fix | Delete
when Integer
[166] Fix | Delete
l = @notifiers[value]
[167] Fix | Delete
raise ErrUndefinedNotifier, value unless l
[168] Fix | Delete
@level_notifier = l
[169] Fix | Delete
else
[170] Fix | Delete
raise ErrUnrecognizedLevel, value unless l
[171] Fix | Delete
end
[172] Fix | Delete
end
[173] Fix | Delete
[174] Fix | Delete
alias level= level_notifier=
[175] Fix | Delete
end
[176] Fix | Delete
[177] Fix | Delete
# A leveled notifier is comparable to the composite group from
[178] Fix | Delete
# CompositeNotifier#notifiers.
[179] Fix | Delete
class LeveledNotifier < AbstractNotifier
[180] Fix | Delete
include Comparable
[181] Fix | Delete
[182] Fix | Delete
# Create a new leveled notifier with the given +base+, and +prefix+ to
[183] Fix | Delete
# send to AbstractNotifier.new
[184] Fix | Delete
#
[185] Fix | Delete
# The given +level+ is used to compare other leveled notifiers in the
[186] Fix | Delete
# CompositeNotifier group to determine whether or not to output
[187] Fix | Delete
# notifications.
[188] Fix | Delete
def initialize(base, level, prefix)
[189] Fix | Delete
super(prefix, base)
[190] Fix | Delete
[191] Fix | Delete
@level = level
[192] Fix | Delete
end
[193] Fix | Delete
[194] Fix | Delete
# The current level of this notifier object
[195] Fix | Delete
attr_reader :level
[196] Fix | Delete
[197] Fix | Delete
# Compares the level of this notifier object with the given +other+
[198] Fix | Delete
# notifier.
[199] Fix | Delete
#
[200] Fix | Delete
# See the Comparable module for more information.
[201] Fix | Delete
def <=>(other)
[202] Fix | Delete
@level <=> other.level
[203] Fix | Delete
end
[204] Fix | Delete
[205] Fix | Delete
# Whether to output messages to the output method, depending on the level
[206] Fix | Delete
# of this notifier object.
[207] Fix | Delete
def notify?
[208] Fix | Delete
@base_notifier.level >= self
[209] Fix | Delete
end
[210] Fix | Delete
end
[211] Fix | Delete
[212] Fix | Delete
# NoMsgNotifier is a LeveledNotifier that's used as the default notifier
[213] Fix | Delete
# when creating a new CompositeNotifier.
[214] Fix | Delete
#
[215] Fix | Delete
# This notifier is used as the +zero+ index, or level +0+, for
[216] Fix | Delete
# CompositeNotifier#notifiers, and will not output messages of any sort.
[217] Fix | Delete
class NoMsgNotifier < LeveledNotifier
[218] Fix | Delete
# Creates a new notifier that should not be used to output messages.
[219] Fix | Delete
def initialize
[220] Fix | Delete
@base_notifier = nil
[221] Fix | Delete
@level = 0
[222] Fix | Delete
@prefix = ""
[223] Fix | Delete
end
[224] Fix | Delete
[225] Fix | Delete
# Ensures notifications are ignored, see AbstractNotifier#notify? for
[226] Fix | Delete
# more information.
[227] Fix | Delete
def notify?
[228] Fix | Delete
false
[229] Fix | Delete
end
[230] Fix | Delete
end
[231] Fix | Delete
[232] Fix | Delete
D_NOMSG = NoMsgNotifier.new # :nodoc:
[233] Fix | Delete
end
[234] Fix | Delete
end
[235] Fix | Delete
[236] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function