switch-exception 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in switch-exception.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ require "switch-exception/version"
2
+
3
+ module SwitchException
4
+ def switch_exception(e, &block)
5
+ sw = ExceptionSwitch.new(e)
6
+ sw.instance_eval(&block)
7
+ raise e unless sw.handled
8
+ end
9
+
10
+ private
11
+ class ExceptionSwitch
12
+ attr_reader :handled
13
+
14
+ def initialize(e)
15
+ @exception = e
16
+ @handled = false
17
+ end
18
+
19
+ def on(*regexi, &block)
20
+ if @handled
21
+ return
22
+ elsif regexi.any? { |re| @exception.message =~ re }
23
+ @handled = true
24
+ block ? block.call(@exception) : nil
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module SwitchException
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "switch-exception/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "switch-exception"
7
+ s.version = SwitchException::VERSION
8
+ s.authors = ["Michael Rykov"]
9
+ s.email = ["mrykov@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Handle exceptions based on message}
12
+ s.description = %q{Handle exceptions based on message}
13
+
14
+ s.rubyforge_project = "switch-exception"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: switch-exception
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Rykov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Handle exceptions based on message
15
+ email:
16
+ - mrykov@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - lib/switch-exception.rb
25
+ - lib/switch-exception/version.rb
26
+ - switch-exception.gemspec
27
+ homepage: ''
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project: switch-exception
47
+ rubygems_version: 1.8.11
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Handle exceptions based on message
51
+ test_files: []