recklessly 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,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .*.sw?
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in recklessly.gemspec
4
+ gemspec
5
+ gem "rake", :require => "false"
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+
5
+ Rake::TestTask.new :test do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ test_files = FileList['test/**/*_test.rb']
9
+ t.test_files = test_files
10
+ t.verbose = true
11
+ end
12
+
@@ -0,0 +1,35 @@
1
+ require "recklessly/version"
2
+ require "hoptoad_notifier"
3
+
4
+ module Recklessly
5
+ module ClassMethods
6
+ def recklessly(&blk)
7
+ Recklessly.yield_and_capture(&blk)
8
+ end
9
+ end
10
+
11
+ def self.included(klass)
12
+ klass.extend ClassMethods
13
+ end
14
+
15
+ def self.rescue=(rescue_proc)
16
+ @rescue = rescue_proc
17
+ end
18
+
19
+ def self.rescue
20
+ @rescue
21
+ end
22
+
23
+ def self.yield_and_capture
24
+ begin
25
+ yield
26
+ rescue Exception => ex
27
+ Recklessly.rescue.call(ex) if Recklessly.rescue
28
+ end
29
+ end
30
+
31
+ def recklessly(&blk)
32
+ Recklessly.yield_and_capture(&blk)
33
+ end
34
+
35
+ end
@@ -0,0 +1,3 @@
1
+ module Recklessly
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "recklessly/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "recklessly"
7
+ s.version = Recklessly::VERSION
8
+ s.authors = ["Glenn Gillen"]
9
+ s.email = ["me@glenngillen.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Execute code but don't raise exceptions.}
12
+ s.description = %q{Allows you to execute code, and then have any exceptions handled in a generic way (like posting to Hoptoad).}
13
+
14
+ s.rubyforge_project = "recklessly"
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
+ end
@@ -0,0 +1,3 @@
1
+ require "test/unit"
2
+ require "#{File.dirname(__FILE__)}/../lib/recklessly"
3
+
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+ class ExceptionalObject
3
+ include Recklessly
4
+
5
+ def self.class_run
6
+ recklessly do
7
+ raise StandardError.new "My class error"
8
+ end
9
+ end
10
+
11
+ def instance_run
12
+ recklessly do
13
+ raise StandardError.new "My instance error"
14
+ end
15
+ end
16
+ end
17
+
18
+ class RecklesslyTest < Test::Unit::TestCase
19
+
20
+ def setup
21
+ @object = ExceptionalObject.new
22
+ end
23
+
24
+ def test_ignores_exceptions
25
+ assert_nothing_raised do
26
+ @object.instance_run
27
+ end
28
+
29
+ assert_nothing_raised do
30
+ ExceptionalObject.class_run
31
+ end
32
+ end
33
+
34
+ def test_runs_proc_on_exception
35
+ my_errors = []
36
+ Recklessly.rescue = Proc.new{|ex| my_errors << ex.message }
37
+ ExceptionalObject.class_run
38
+ @object.instance_run
39
+ assert my_errors.include? "My class error"
40
+ assert my_errors.include? "My instance error"
41
+ end
42
+ end
43
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recklessly
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Glenn Gillen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-10 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Allows you to execute code, and then have any exceptions handled in a generic way (like posting to Hoptoad).
22
+ email:
23
+ - me@glenngillen.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - lib/recklessly.rb
35
+ - lib/recklessly/version.rb
36
+ - recklessly.gemspec
37
+ - test/helper.rb
38
+ - test/recklessly_test.rb
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: recklessly
68
+ rubygems_version: 1.8.15
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Execute code but don't raise exceptions.
72
+ test_files:
73
+ - test/helper.rb
74
+ - test/recklessly_test.rb