./lib/lux/rescue_from/rescue_from.rb in lux-fw-0.1.17 vs ./lib/lux/rescue_from/rescue_from.rb in lux-fw-0.1.35
- old
+ new
@@ -12,11 +12,11 @@
# @@rescue_from_ivar.call { main }
class Lux::RescueFrom
class << self
- def define(klass)
+ def define klass
ClassAttributes.define klass, :rescue_from_hash
klass.class_eval %[
@@rescue_from_ivar = Lux::RescueFrom.new
def self.rescue_from(name, &block)
@@ -30,31 +30,33 @@
def initialize
@rescues = {}
end
- def add(name, &block)
+ def add name, &block
die ":#{name} is not allowed rescue name, only allowed are :default and :allways" if name.is_symbol? && ![:default, :allways].index(name)
@rescues[name.to_s] = block
end
- def call
+ # we pass context so we can execute errors it object context
+ def call context
begin
yield
rescue Exception => e
raise e unless Lux.page
return if Lux.page.body && Lux.page.status
if proc = @rescues[e.class.to_s]
proc.call(e.message)
- elsif @rescues['default'] # catch them all
- @rescues['default'].call(e.message)
+ context.instance_exec e.message, &proc
+ elsif proc = @rescues['default'] # catch them all
+ context.instance_exec e.message, &proc
else
raise e
end
- @rescues['allways'].call(e.message) if @rescues['allways']
+ context.instance_exec e.message, &@rescues['allways'] if @rescues['allways']
Lux.page.status e.class
end
end
end
\ No newline at end of file