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