Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/share/ruby
File: e2mmap.rb
# frozen_string_literal: true
[0] Fix | Delete
#
[1] Fix | Delete
#--
[2] Fix | Delete
# e2mmap.rb - for Ruby 1.1
[3] Fix | Delete
# $Release Version: 2.0$
[4] Fix | Delete
# $Revision: 1.10 $
[5] Fix | Delete
# by Keiju ISHITSUKA
[6] Fix | Delete
#
[7] Fix | Delete
#++
[8] Fix | Delete
#
[9] Fix | Delete
# Helper module for easily defining exceptions with predefined messages.
[10] Fix | Delete
#
[11] Fix | Delete
# == Usage
[12] Fix | Delete
#
[13] Fix | Delete
# 1.
[14] Fix | Delete
# class Foo
[15] Fix | Delete
# extend Exception2MessageMapper
[16] Fix | Delete
# def_e2message ExistingExceptionClass, "message..."
[17] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[18] Fix | Delete
# ...
[19] Fix | Delete
# end
[20] Fix | Delete
#
[21] Fix | Delete
# 2.
[22] Fix | Delete
# module Error
[23] Fix | Delete
# extend Exception2MessageMapper
[24] Fix | Delete
# def_e2message ExistingExceptionClass, "message..."
[25] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[26] Fix | Delete
# ...
[27] Fix | Delete
# end
[28] Fix | Delete
# class Foo
[29] Fix | Delete
# include Error
[30] Fix | Delete
# ...
[31] Fix | Delete
# end
[32] Fix | Delete
#
[33] Fix | Delete
# foo = Foo.new
[34] Fix | Delete
# foo.Fail ....
[35] Fix | Delete
#
[36] Fix | Delete
# 3.
[37] Fix | Delete
# module Error
[38] Fix | Delete
# extend Exception2MessageMapper
[39] Fix | Delete
# def_e2message ExistingExceptionClass, "message..."
[40] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[41] Fix | Delete
# ...
[42] Fix | Delete
# end
[43] Fix | Delete
# class Foo
[44] Fix | Delete
# extend Exception2MessageMapper
[45] Fix | Delete
# include Error
[46] Fix | Delete
# ...
[47] Fix | Delete
# end
[48] Fix | Delete
#
[49] Fix | Delete
# Foo.Fail NewExceptionClass, arg...
[50] Fix | Delete
# Foo.Fail ExistingExceptionClass, arg...
[51] Fix | Delete
#
[52] Fix | Delete
#
[53] Fix | Delete
module Exception2MessageMapper
[54] Fix | Delete
[55] Fix | Delete
E2MM = Exception2MessageMapper # :nodoc:
[56] Fix | Delete
[57] Fix | Delete
def E2MM.extend_object(cl)
[58] Fix | Delete
super
[59] Fix | Delete
cl.bind(self) unless cl < E2MM
[60] Fix | Delete
end
[61] Fix | Delete
[62] Fix | Delete
def bind(cl)
[63] Fix | Delete
self.module_eval "#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1
[64] Fix | Delete
begin;
[65] Fix | Delete
def Raise(err = nil, *rest)
[66] Fix | Delete
Exception2MessageMapper.Raise(self.class, err, *rest)
[67] Fix | Delete
end
[68] Fix | Delete
alias Fail Raise
[69] Fix | Delete
[70] Fix | Delete
class << self
[71] Fix | Delete
undef included
[72] Fix | Delete
end
[73] Fix | Delete
def self.included(mod)
[74] Fix | Delete
mod.extend Exception2MessageMapper
[75] Fix | Delete
end
[76] Fix | Delete
end;
[77] Fix | Delete
end
[78] Fix | Delete
[79] Fix | Delete
# Fail(err, *rest)
[80] Fix | Delete
# err: exception
[81] Fix | Delete
# rest: message arguments
[82] Fix | Delete
#
[83] Fix | Delete
def Raise(err = nil, *rest)
[84] Fix | Delete
E2MM.Raise(self, err, *rest)
[85] Fix | Delete
end
[86] Fix | Delete
alias Fail Raise
[87] Fix | Delete
alias fail Raise
[88] Fix | Delete
[89] Fix | Delete
# def_e2message(c, m)
[90] Fix | Delete
# c: exception
[91] Fix | Delete
# m: message_form
[92] Fix | Delete
# define exception c with message m.
[93] Fix | Delete
#
[94] Fix | Delete
def def_e2message(c, m)
[95] Fix | Delete
E2MM.def_e2message(self, c, m)
[96] Fix | Delete
end
[97] Fix | Delete
[98] Fix | Delete
# def_exception(n, m, s)
[99] Fix | Delete
# n: exception_name
[100] Fix | Delete
# m: message_form
[101] Fix | Delete
# s: superclass(default: StandardError)
[102] Fix | Delete
# define exception named ``c'' with message m.
[103] Fix | Delete
#
[104] Fix | Delete
def def_exception(n, m, s = StandardError)
[105] Fix | Delete
E2MM.def_exception(self, n, m, s)
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
#
[109] Fix | Delete
# Private definitions.
[110] Fix | Delete
#
[111] Fix | Delete
# {[class, exp] => message, ...}
[112] Fix | Delete
@MessageMap = {}
[113] Fix | Delete
[114] Fix | Delete
# E2MM.def_e2message(k, e, m)
[115] Fix | Delete
# k: class to define exception under.
[116] Fix | Delete
# e: exception
[117] Fix | Delete
# m: message_form
[118] Fix | Delete
# define exception c with message m.
[119] Fix | Delete
#
[120] Fix | Delete
def E2MM.def_e2message(k, c, m)
[121] Fix | Delete
E2MM.instance_eval{@MessageMap[[k, c]] = m}
[122] Fix | Delete
c
[123] Fix | Delete
end
[124] Fix | Delete
[125] Fix | Delete
# E2MM.def_exception(k, n, m, s)
[126] Fix | Delete
# k: class to define exception under.
[127] Fix | Delete
# n: exception_name
[128] Fix | Delete
# m: message_form
[129] Fix | Delete
# s: superclass(default: StandardError)
[130] Fix | Delete
# define exception named ``c'' with message m.
[131] Fix | Delete
#
[132] Fix | Delete
def E2MM.def_exception(k, n, m, s = StandardError)
[133] Fix | Delete
e = Class.new(s)
[134] Fix | Delete
E2MM.instance_eval{@MessageMap[[k, e]] = m}
[135] Fix | Delete
k.module_eval {remove_const(n)} if k.const_defined?(n, false)
[136] Fix | Delete
k.const_set(n, e)
[137] Fix | Delete
end
[138] Fix | Delete
[139] Fix | Delete
# Fail(klass, err, *rest)
[140] Fix | Delete
# klass: class to define exception under.
[141] Fix | Delete
# err: exception
[142] Fix | Delete
# rest: message arguments
[143] Fix | Delete
#
[144] Fix | Delete
def E2MM.Raise(klass = E2MM, err = nil, *rest)
[145] Fix | Delete
if form = e2mm_message(klass, err)
[146] Fix | Delete
b = $@.nil? ? caller(1) : $@
[147] Fix | Delete
b.shift if b[0] =~ /^#{Regexp.quote(__FILE__)}:/
[148] Fix | Delete
raise err, sprintf(form, *rest), b
[149] Fix | Delete
else
[150] Fix | Delete
E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
[151] Fix | Delete
end
[152] Fix | Delete
end
[153] Fix | Delete
class << E2MM
[154] Fix | Delete
alias Fail Raise
[155] Fix | Delete
end
[156] Fix | Delete
[157] Fix | Delete
def E2MM.e2mm_message(klass, exp)
[158] Fix | Delete
for c in klass.ancestors
[159] Fix | Delete
if mes = @MessageMap[[c,exp]]
[160] Fix | Delete
m = klass.instance_eval('"' + mes + '"')
[161] Fix | Delete
return m
[162] Fix | Delete
end
[163] Fix | Delete
end
[164] Fix | Delete
nil
[165] Fix | Delete
end
[166] Fix | Delete
class << self
[167] Fix | Delete
alias message e2mm_message
[168] Fix | Delete
end
[169] Fix | Delete
[170] Fix | Delete
E2MM.def_exception(E2MM,
[171] Fix | Delete
:ErrNotRegisteredException,
[172] Fix | Delete
"not registered exception(%s)")
[173] Fix | Delete
end
[174] Fix | Delete
[175] Fix | Delete
[176] Fix | Delete
[177] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function