Sha256: a8eba4e5d47d4f10dec4a49d33e953cecdbf94d8567522b3ada518bd504c9265
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
# coding: UTF-8 module Rescue module Controller module ClassMethods def rescue_associate *klasses, &block options = klasses.extract_options! unless block_given? if options.has_key?(:with) if options[:with].is_a?(Integer) block = lambda {|e| send(Rescue.config.respond_name, options[:with], e) } elsif options[:with].is_a?(Proc) block = options[:with] end else raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument." end end klasses.each do |klass| key = if klass.is_a?(Class) && klass <= Exception klass.name elsif klass.is_a?(String) || klass.is_a?(Symbol) if options.has_key?(:superclass) Rescue::Bind.define_error_class klass, options[:superclass] else Rescue::Bind.define_error_class klass, StandardError end klass else raise ArgumentError, "#{klass} is neither an Exception nor a String" end self.rescue_handlers += [[key, block]] end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rescue-dog-0.2.1 | lib/rescue/controller.rb |
rescue-dog-0.2.0 | lib/rescue/controller.rb |