Module: Exception2MessageMapper
Relationships & Source Files | |
Defined in: | lib/e2mmap.rb, lib/e2mmap/version.rb |
Overview
Helper module for easily defining exceptions with predefined messages.
Usage
1.
class Foo
extend Exception2MessageMapper
def_e2message ExistingExceptionClass, "message..."
def_exception :NewExceptionClass, "message..."[, superclass]
#...
end
2.
module Error
extend Exception2MessageMapper
def_e2message ExistingExceptionClass, "message..."
def_exception :NewExceptionClass, "message..."[, superclass]
#...
end
class Foo
include Error
#...
end
foo = Foo.new
foo.Fail ....
3.
module Error
extend Exception2MessageMapper
def_e2message ExistingExceptionClass, "message..."
def_exception :NewExceptionClass, "message..."[, superclass]
#...
end
class Foo
extend Exception2MessageMapper
include Error
#...
end
Foo.Fail NewExceptionClass, arg...
Foo.Fail ExistingExceptionClass, arg...
Constant Summary
-
E2MM =
Internal use only
# File 'lib/e2mmap.rb', line 57Exception2MessageMapper
-
VERSION =
# File 'lib/e2mmap/version.rb', line 2"0.1.0"
Class Method Summary
-
.def_e2message(k, c, m)
E2MM.def_e2message
(k, e, m). -
.def_exception(k, n, m, s = StandardError)
E2MM.def_exception
(k, n, m, s). - .e2mm_message(klass, exp) (also: .message)
- .extend_object(cl)
-
Fail(klass = E2MM, err = nil, *rest)
Alias for .Raise.
-
.message(klass, exp)
Alias for .e2mm_message.
-
Raise(klass = E2MM, err = nil, *rest)
(also: .Fail)
Fail(klass, err, *rest).
Instance Method Summary
- #bind(cl)
-
#def_e2message(c, m)
def_e2message(c, m).
-
#def_exception(n, m, s = StandardError)
def_exception(n, m, s).
-
#fail(err = nil, *rest)
Alias for #Raise.
-
Fail(err = nil, *rest)
Alias for #Raise.
-
Raise(err = nil, *rest)
(also: #Fail, #fail)
Fail(err, *rest).
Class Method Details
.def_e2message(k, c, m)
E2MM.def_e2message
(k, e, m)
k: class to define exception under.
e: exception
m: message_form
define exception c with message m.
.def_exception(k, n, m, s = StandardError)
E2MM.def_exception
(k, n, m, s)
k: class to define exception under.
n: exception_name
m: message_form
s: superclass(default: StandardError)
define exception named ``c'' with message m.
.e2mm_message(klass, exp) Also known as: .message
[ GitHub ]# File 'lib/e2mmap.rb', line 159
def E2MM. (klass, exp) for c in klass.ancestors if mes = @MessageMap[[c,exp]] m = klass.instance_eval('"' + mes + '"') return m end end nil end
.extend_object(cl)
[ GitHub ]Fail(klass = E2MM, err = nil, *rest)
Alias for .Raise.
# File 'lib/e2mmap.rb', line 156
alias Fail Raise
.message(klass, exp)
Alias for .e2mm_message.
# File 'lib/e2mmap.rb', line 169
alias
Raise(klass = E2MM, err = nil, *rest) Also known as: .Fail
Fail(klass, err, *rest)
klass: class to define exception under.
err: exception
rest: message arguments
Instance Method Details
#bind(cl)
[ GitHub ]# File 'lib/e2mmap.rb', line 64
def bind(cl) self.module_eval "#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1 begin; def Raise(err = nil, *rest) Exception2MessageMapper.Raise(self.class, err, *rest) end alias Fail Raise class << self undef included end def self.included(mod) mod.extend Exception2MessageMapper end end; end
#def_e2message(c, m)
def_e2message(c, m)
c: exception
m: message_form
define exception c with message m.
# File 'lib/e2mmap.rb', line 96
def (c, m) E2MM. (self, c, m) end
#def_exception(n, m, s = StandardError)
def_exception(n, m, s)
n: exception_name
m: message_form
s: superclass(default: StandardError)
define exception named ``c'' with message m.
# File 'lib/e2mmap.rb', line 106
def def_exception(n, m, s = StandardError) E2MM.def_exception(self, n, m, s) end
Fail(err = nil, *rest)
Alias for #Raise.
# File 'lib/e2mmap.rb', line 88
alias Fail Raise
#fail(err = nil, *rest)
Alias for #Raise.
# File 'lib/e2mmap.rb', line 89
alias fail Raise
Raise(err = nil, *rest) Also known as: #Fail, #fail
Fail(err, *rest)
err: exception
rest: message arguments