exceptions 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be972ecb6d34a925191b4337f17c8542296937e9
4
+ data.tar.gz: fec33cc75f361d78e1db22cb27a73638db79fcb5
5
+ SHA512:
6
+ metadata.gz: 53626569e8487494a85b87544fcbac4b4ecf6437f08514e8552eb9a8bdefc828b8fd673748dcc0207d54124b0aea2b64ae8bc7e73c7d1369a40718f5d5e7f1eb
7
+ data.tar.gz: 23b957be7f746255410972b339453209c3caba0bf1f9db807443597c6034696421941a6bca834c2615819e140dc3242b7c2eb03c9943281ffbc70c206c6e3165
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exceptions.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric J. Holmes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Exceptions
2
+
3
+ Exceptions is a Ruby gem that provides the right amount of abstraction for doing exception
4
+ tracking in Ruby.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'exceptions'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```ruby
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+
22
+ ```ruby
23
+ $ gem install exceptions
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ **Track an exception**
29
+
30
+ ```ruby
31
+ Exceptions.notify(StandardError.new("Boom"))
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exceptions/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exceptions"
8
+ spec.version = Exceptions::VERSION
9
+ spec.authors = ["Eric J. Holmes"]
10
+ spec.email = ["eric@ejholmes.net"]
11
+ spec.description = %q{Exceptions is a Ruby gem for exception tracking.}
12
+ spec.summary = %q{Exceptions is a Ruby gem for exception tracking.}
13
+ spec.homepage = "https://github.com/remind101/exceptions"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "honeybadger"
25
+ end
@@ -0,0 +1,53 @@
1
+ require 'exceptions/version'
2
+ require 'exceptions/configuration'
3
+ require 'exceptions/result'
4
+ require 'exceptions/backend'
5
+ require 'exceptions/backends'
6
+
7
+ module Exceptions
8
+ class << self
9
+ # Public: Forwards the exception to the configured backend.
10
+ #
11
+ # exception - An Exception object.
12
+ # options - A Hash of options to pass to the backend.
13
+ #
14
+ # Returns a Result object.
15
+ def notify(exception, options = {})
16
+ backend.notify exception, options
17
+ end
18
+
19
+ # Public: Set the context.
20
+ #
21
+ # Returns nothing.
22
+ def context(ctx)
23
+ backend.context ctx
24
+ end
25
+
26
+ # Public: Clear the context.
27
+ #
28
+ # Returns nothing.
29
+ def clear_context
30
+ backend.clear_context
31
+ end
32
+
33
+ # Public: The configuration object.
34
+ #
35
+ # Returns a Configuration instance.
36
+ def configuration
37
+ @configuration ||= Configuration.new
38
+ end
39
+
40
+ # Public: Configure the configuration.
41
+ #
42
+ # Yields the Configuration object.
43
+ def configure
44
+ yield configuration
45
+ end
46
+
47
+ private
48
+
49
+ def backend
50
+ configuration.backend
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ module Exceptions
2
+ # Public: Backend is an abstract class that documents the interface
3
+ # for an exception tracking backend.
4
+ class Backend
5
+ # Public: Notify should be implemented by classes that inherit from Backend to
6
+ # do something with the exception. Implementers of this interface can optionally
7
+ # return a Result object which can include things like an exception id from
8
+ # an external service.
9
+ #
10
+ # exception - An Exception object.
11
+ # options - A Hash of options.
12
+ #
13
+ # Returns nil or a Result object.
14
+ def notify(exception)
15
+ raise NotImplementedError
16
+ end
17
+
18
+ # Public: Context can be used to set global context.
19
+ #
20
+ # ctx - A Hash of contextual information.
21
+ #
22
+ # Returns nothing.
23
+ def context(ctx)
24
+ raise NotImplementedError
25
+ end
26
+
27
+ # Public: Clear should clear the context.
28
+ #
29
+ # Returns nothing.
30
+ def clear_context
31
+ raise NotImplementedError
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Exceptions
2
+ module Backends
3
+ autoload :Null, 'exceptions/backends/null'
4
+ autoload :Raiser, 'exceptions/backends/raiser'
5
+ autoload :Multi, 'exceptions/backends/multi'
6
+ autoload :Logger, 'exceptions/backends/logger'
7
+ autoload :Honeybadger, 'exceptions/backends/honeybadger'
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require 'honeybadger'
2
+
3
+ module Exceptions
4
+ module Backends
5
+ # Public: The Honeybadger backend is a Backend implementation that sends the
6
+ # exception to Honeybadger.
7
+ class Honeybadger < Backend
8
+ def notify(exception, options = {})
9
+ if id = ::Honeybadger.notify_or_ignore(exception, options)
10
+ Result.new id
11
+ else
12
+ BadResult.new
13
+ end
14
+ end
15
+
16
+ def context(ctx)
17
+ ::Honeybadger.context ctx
18
+ end
19
+
20
+ def clear_context
21
+ ::Honeybadger.clear!
22
+ end
23
+
24
+ class Result < ::Exceptions::Result
25
+ def url
26
+ "https://www.honeybadger.io/notice/#{id}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Exceptions
2
+ module Backends
3
+ # Public: Logger is an implementation of the Backend interface that logs exceptions
4
+ # to STDOUT.
5
+ class Logger < Backend
6
+ attr_accessor :logger
7
+
8
+ def initialize(logger = ::Logger.new(STDOUT))
9
+ @logger = logger
10
+ end
11
+
12
+ def notify(exception, options = {})
13
+ logger.info exception
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Exceptions
2
+ module Backends
3
+ # Public: Multi is an implementation of the Backend interface for wrapping multiple
4
+ # backends as a single Backend.
5
+ class Multi < Backend
6
+ attr_reader :backends
7
+
8
+ def initialize(*backends)
9
+ @backends = backends
10
+ end
11
+
12
+ def notify(exception, options = {})
13
+ backends.each do |backend|
14
+ backend.notify exception, options
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Exceptions
2
+ module Backends
3
+ # Public: Null is an implementation of the Backend interface that does nothing.
4
+ class Null < Backend
5
+ def notify(exception, options = {}); end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Exceptions
2
+ module Backends
3
+ # Public: Raiser is an implementation of the Backend interface that raises the exception.
4
+ class Raiser < Backend
5
+ def notify(exception, options = {})
6
+ raise exception
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Exceptions
2
+ class Configuration
3
+ # The exception tracking backend to use.
4
+ attr_accessor :backend
5
+
6
+ def backend
7
+ @backend ||= Backends::Honeybadger.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Exceptions
2
+ # Public: Result represents a result of an Exception notification. It can be used
3
+ # to return information about the exception.
4
+ class Result
5
+ attr_reader :id
6
+
7
+ def initialize(id)
8
+ @id = id
9
+ end
10
+
11
+ def url
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def ok?
16
+ true
17
+ end
18
+ end
19
+
20
+ # Public: BadResult can be returned when there's a failure.
21
+ class BadResult
22
+ def ok?
23
+ false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Exceptions
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exceptions::Backends::Honeybadger, backend: :honeybadger do
4
+ before do
5
+ Exceptions.clear_context
6
+ end
7
+
8
+ describe '#notify' do
9
+ it 'sends the exception to honeybadger' do
10
+ Exceptions.context(request_id: '1234')
11
+ result = Exceptions.notify(boom)
12
+ expect(result.id).to_not be_empty
13
+ expect(result.url).to_not be_empty
14
+ end
15
+ end
16
+
17
+ describe '#context' do
18
+ it 'sets the honeybadger context' do
19
+ expect {
20
+ Exceptions.context(request_id: '1234')
21
+ }.to change { Thread.current[:honeybadger_context] }.from(nil).to(request_id: '1234')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exceptions::Backends::Logger, backend: :logger do
4
+ describe '.notify' do
5
+ it 'logs the exception to stdout' do
6
+ Exceptions.notify(boom)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default, :test
3
+
4
+ RSpec.configure do |config|
5
+ config.order = 'random'
6
+ config.filter_run focus: true
7
+ config.run_all_when_everything_filtered = true
8
+
9
+ config.around(:each) do |example|
10
+ if backend = example.metadata[:backend]
11
+ with_backend(BACKENDS[backend]) do
12
+ example.run
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # Requires supporting ruby files with custom matchers and macros, etc,
19
+ # in spec/support/ and its subdirectories.
20
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
21
+
22
+ BACKENDS = {
23
+ honeybadger: Exceptions::Backends::Honeybadger.new,
24
+ multi: Exceptions::Backends::Multi.new(Exceptions::Backends::Null.new),
25
+ logger: Exceptions::Backends::Logger.new
26
+ }
27
+
28
+ Exceptions.configure do |config|
29
+ config.backend = BACKENDS[:multi]
30
+ end
31
+
32
+ def with_backend(backend)
33
+ old = Exceptions.configuration.backend
34
+ Exceptions.configuration.backend = backend
35
+ yield
36
+ ensure
37
+ Exceptions.configuration.backend = old
38
+ end
39
+
40
+ def backend
41
+ Exceptions.configuration.backend
42
+ end
43
+
44
+ def boom
45
+ StandardError.new("Boom")
46
+ end
@@ -0,0 +1,6 @@
1
+ require 'honeybadger'
2
+
3
+ Honeybadger.configure do |config|
4
+ config.api_key = ENV.fetch('HONEYBADGER_API_KEY')
5
+ config.environment_name = 'testing'
6
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exceptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric J. Holmes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: honeybadger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Exceptions is a Ruby gem for exception tracking.
70
+ email:
71
+ - eric@ejholmes.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - exceptions.gemspec
83
+ - lib/exceptions.rb
84
+ - lib/exceptions/backend.rb
85
+ - lib/exceptions/backends.rb
86
+ - lib/exceptions/backends/honeybadger.rb
87
+ - lib/exceptions/backends/logger.rb
88
+ - lib/exceptions/backends/multi.rb
89
+ - lib/exceptions/backends/null.rb
90
+ - lib/exceptions/backends/raiser.rb
91
+ - lib/exceptions/configuration.rb
92
+ - lib/exceptions/result.rb
93
+ - lib/exceptions/version.rb
94
+ - spec/exceptions/backends/honeybadger/integration_spec.rb
95
+ - spec/exceptions/backends/logger/integration_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/support/honeybadger.rb
98
+ homepage: https://github.com/remind101/exceptions
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.0.14
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Exceptions is a Ruby gem for exception tracking.
122
+ test_files:
123
+ - spec/exceptions/backends/honeybadger/integration_spec.rb
124
+ - spec/exceptions/backends/logger/integration_spec.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/honeybadger.rb