safely 0.1.0pre

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ group :development do
10
+ gem "toadhopper"
11
+
12
+ gem "rspec", "~> 2.5.0"
13
+ gem "yard", "~> 0.6.0"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.5.2"
16
+ gem "rcov", ">= 0"
17
+ gem "mocha"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ mocha (0.9.12)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.5.0)
14
+ rspec-core (~> 2.5.0)
15
+ rspec-expectations (~> 2.5.0)
16
+ rspec-mocks (~> 2.5.0)
17
+ rspec-core (2.5.1)
18
+ rspec-expectations (2.5.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.5.0)
21
+ toadhopper (1.1)
22
+ yard (0.6.7)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ jeweler (~> 1.5.2)
30
+ mocha
31
+ rcov
32
+ rspec (~> 2.5.0)
33
+ toadhopper
34
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kenneth Kalmer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = safely
2
+
3
+ Safely is a simple exception handling and alerting mechanism extract from the daemon-kit[http://github.com/kennethkalmer/daemon-kit] project.
4
+
5
+ Safely currently supports error reporting to Hoptoad via the Toadhopper[http://github.com/toolmantim/toadhopper] gem. Future support will
6
+ include reporting errors to log files and via email.
7
+
8
+ == Installation
9
+
10
+ In your Gemfile
11
+
12
+ gem "toadhopper", "~> 1.1"
13
+ gem "safely", "~> 0.1"
14
+
15
+ Or directly
16
+
17
+ gem install toadhopper -v "~> 1.1"
18
+ gem install safely -v "~> 0.1"
19
+
20
+ Although Safely currently only supports Toadhopper, it doesn't specify it as a dependency. This allows for
21
+ future strategies to be added and giving users the choice on which strategy to use without bloating their
22
+ projects.
23
+
24
+ == Usage
25
+
26
+ require 'toadhopper'
27
+ require 'safely'
28
+
29
+ # Configure
30
+ Safely.configure do |c|
31
+ c.hoptoad_key = 'XXXXXXXX'
32
+ end
33
+
34
+ # Run your code
35
+ safely do
36
+ do_something_dangerous!
37
+ end
38
+
39
+ == TODO
40
+
41
+ * Support for mail exceptions
42
+ * Support for logging exceptions
43
+ * Fine-tine strategies
44
+ * Support for trapping exceptions on exit
45
+
46
+ == Contributing to safely
47
+
48
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
49
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
50
+ * Fork the project
51
+ * Start a feature/bugfix branch
52
+ * Commit and push until you are happy with your contribution
53
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
54
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
55
+
56
+ == Copyright
57
+
58
+ Copyright (c) 2011 Kenneth Kalmer. See LICENSE.txt for
59
+ further details.
60
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ $:.unshift File.expand_path('../lib', __FILE__)
13
+ require 'safely'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "safely"
19
+ gem.homepage = "http://github.com/kennethkalmer/safely"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Safely run your code, keep track of exceptions}
22
+ gem.description = %Q{Safely run your code in a loving error reporting embrace}
23
+ gem.email = "kenneth.kalmer@gmail.com"
24
+ gem.authors = ["Kenneth Kalmer"]
25
+ gem.version = Safely::VERSION
26
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
27
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
28
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
29
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rspec/core'
34
+ require 'rspec/core/rake_task'
35
+ RSpec::Core::RakeTask.new(:spec) do |spec|
36
+ spec.pattern = FileList['spec/**/*_spec.rb']
37
+ end
38
+
39
+ #RSpec::Core::RakeTask.new(:rcov) do |spec|
40
+ # spec.pattern = 'spec/**/*_spec.rb'
41
+ # spec.rcov = true
42
+ #end
43
+
44
+ task :default => :spec
45
+
46
+ require 'yard'
47
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ module Safely
2
+ class Config
3
+ # Hoptoad API key
4
+ attr_accessor :hoptoad_key
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Safely
2
+ module Mixin
3
+
4
+ def safely
5
+ Safely.load_strategies!
6
+
7
+ begin
8
+ yield
9
+ rescue => e
10
+ Safely.report!( e )
11
+ end
12
+ end
13
+
14
+ end
15
+ end
data/lib/safely.rb ADDED
@@ -0,0 +1,51 @@
1
+ $:.unshift File.expand_path('../', __FILE__)
2
+
3
+ module Safely
4
+
5
+ VERSION = "0.1.0pre"
6
+
7
+ autoload :Config, 'safely/config'
8
+ autoload :Mixin, 'safely/mixin'
9
+
10
+ class << self
11
+
12
+ def reset!
13
+ self.config = nil
14
+ end
15
+
16
+ def configure
17
+ yield self.config
18
+ end
19
+
20
+ def config
21
+ @config ||= Safely::Config.new
22
+ end
23
+
24
+ def load_strategies!
25
+ begin
26
+ require 'toadhopper'
27
+ rescue LoadError
28
+ # Print warning
29
+ end
30
+ end
31
+
32
+ def report!( exception )
33
+ if defined?( Toadhopper ) && !config.hoptoad_key.nil?
34
+ Toadhopper( config.hoptoad_key ).post!( exception )
35
+ else
36
+ STDERR.puts "Toadhopper not available or not configured!"
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def config=( config )
43
+ @config = config
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ Object.send( :include, Safely::Mixin )
51
+ Object.send( :extend, Safely::Mixin )
data/safely.gemspec ADDED
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{safely}
8
+ s.version = "0.1.0pre"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kenneth Kalmer"]
12
+ s.date = %q{2011-04-14}
13
+ s.description = %q{Safely run your code in a loving error reporting embrace}
14
+ s.email = %q{kenneth.kalmer@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/safely.rb",
29
+ "lib/safely/config.rb",
30
+ "lib/safely/mixin.rb",
31
+ "safely.gemspec",
32
+ "spec/config_spec.rb",
33
+ "spec/safely_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/kennethkalmer/safely}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.7.2}
40
+ s.summary = %q{Safely run your code, keep track of exceptions}
41
+ s.test_files = [
42
+ "spec/config_spec.rb",
43
+ "spec/safely_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<toadhopper>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
53
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
54
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
56
+ s.add_development_dependency(%q<rcov>, [">= 0"])
57
+ s.add_development_dependency(%q<mocha>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<toadhopper>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
61
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ s.add_dependency(%q<mocha>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<toadhopper>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
70
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<mocha>, [">= 0"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Safely::Config do
4
+ describe "Hoptoad" do
5
+ it { should respond_to(:hoptoad_key) }
6
+ it { should respond_to(:hoptoad_key=) }
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Safely do
4
+ describe "configuration" do
5
+ it "should accept a Hoptoad api key" do
6
+ Safely.configure do |c|
7
+ c.hoptoad_key = "foo"
8
+ end
9
+
10
+ Safely.config.hoptoad_key.should == "foo"
11
+ end
12
+ end
13
+
14
+ describe "integration" do
15
+ it "should be mixed into Kernel" do
16
+ Object.should respond_to(:safely)
17
+ end
18
+
19
+ it "should be mixed into instances" do
20
+ Object.new.should respond_to(:safely)
21
+ end
22
+ end
23
+
24
+ describe "strategies" do
25
+ it "should load Toadhopper if present" do
26
+ Safely.load_strategies!
27
+
28
+ defined?( Toadhopper ).should be_true
29
+ end
30
+ end
31
+
32
+ describe "usage" do
33
+ it "should report exceptions to hoptoad" do
34
+ Safely.configure do |c|
35
+ c.hoptoad_key = "foo"
36
+ end
37
+
38
+ Toadhopper.any_instance.expects(:post!)
39
+
40
+ safely do
41
+ raise "Hello"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'safely'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.mock_with(:mocha)
12
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safely
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 5
5
+ version: 0.1.0pre
6
+ platform: ruby
7
+ authors:
8
+ - Kenneth Kalmer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-14 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: toadhopper
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.6.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: jeweler
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.5.2
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: rcov
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: mocha
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
92
+ description: Safely run your code in a loving error reporting embrace
93
+ email: kenneth.kalmer@gmail.com
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - .rspec
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - Rakefile
109
+ - VERSION
110
+ - lib/safely.rb
111
+ - lib/safely/config.rb
112
+ - lib/safely/mixin.rb
113
+ - safely.gemspec
114
+ - spec/config_spec.rb
115
+ - spec/safely_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: http://github.com/kennethkalmer/safely
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: -1229273114892724216
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">"
138
+ - !ruby/object:Gem::Version
139
+ version: 1.3.1
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.7.2
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Safely run your code, keep track of exceptions
147
+ test_files:
148
+ - spec/config_spec.rb
149
+ - spec/safely_spec.rb
150
+ - spec/spec_helper.rb