exception_notification-rake 0.0.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Nik Haldimann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ exception_notification-rake
2
+ ===========================
3
+
4
+ An extension of the exception_notification gem to support sending mail upon failures in Rake tasks. Currently in development.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/*_test.rb']
9
+ test.verbose = true
10
+ test.warning = true
11
+ end
12
+
13
+ task :default => [:test]
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'exception_notifier/rake/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'exception_notification-rake'
6
+ s.version = ExceptionNotifier::Rake::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Nik Haldimann']
9
+ s.email = ['nhaldimann@gmail.com']
10
+ s.homepage = 'https://github.com/nikhaldi/exception_notification-rake'
11
+ s.summary = 'Sending exception notifications upon Rake task failures'
12
+ s.description = 'An extension of the exception_notification gem to support' +
13
+ ' sending mail upon failures in Rake tasks'
14
+
15
+ s.add_runtime_dependency 'exception_notification', '~> 3.0.0'
16
+ # TODO how to specify rake dependency?
17
+ s.add_development_dependency 'rake'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ['lib']
23
+ end
@@ -0,0 +1,46 @@
1
+ require 'exception_notifier'
2
+
3
+ class ExceptionNotifier
4
+ class Rake
5
+
6
+ ALWAYS_TRUE = lambda { true }
7
+
8
+ @notifier_options = {}
9
+
10
+ def self.configured?
11
+ !@notifier_options.empty?
12
+ end
13
+
14
+ def self.configure(config, options = {})
15
+ # TODO add ExceptionNotifier to middleware if needed
16
+ @notifier_options.merge!(default_notifier_options)
17
+ @notifier_options.merge!(options)
18
+ end
19
+
20
+ def self.default_notifier_options
21
+ {
22
+ :email_prefix => "[Rake Failure] ",
23
+ # TODO add stdin/stderr sections with captured output
24
+ :background_sections => %w(backtrace),
25
+ # TODO include this only if ExceptionNotifer not already in use
26
+ :ignore_if => ALWAYS_TRUE,
27
+ }
28
+ end
29
+
30
+ def self.notifier_options
31
+ @notifier_options
32
+ end
33
+
34
+ def self.maybe_deliver_notification(exception)
35
+ # TODO needs test
36
+ if configured?
37
+ ExceptionNotifier::Notifier.background_exception_notification(
38
+ exception, notifier_options).deliver
39
+ end
40
+ end
41
+
42
+ def self.reset_for_test
43
+ @notifier_options = {}
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ # Monkey patching patterns lifted from
2
+ # https://github.com/thoughtbot/airbrake/blob/master/lib/airbrake/rake_handler.rb
3
+ class ExceptionNotifier
4
+ module RakePatch
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ alias_method :display_error_message_without_notifications, :display_error_message
8
+ alias_method :display_error_message, :display_error_message_with_notifications
9
+ end
10
+ end
11
+
12
+ def display_error_message_with_notifications(ex)
13
+ ExceptionNotifier::Rake.maybe_deliver_notification(ex)
14
+ display_error_message_without_notifications(ex)
15
+ end
16
+ end
17
+ end
18
+
19
+ # Only do this if we're actually in a Rake context. In some contexts (e.g.,
20
+ # in the Rails console) Rake might not be defined.
21
+ if Object.const_defined? :Rake
22
+ Rake.application.instance_eval do
23
+ class << self
24
+ include ExceptionNotifier::RakePatch
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class ExceptionNotifier
2
+ class Rake
3
+ VERSION = '0.0.1.alpha1'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'exception_notifier/rake/rake'
2
+ require 'exception_notifier/rake/rake_patch'
3
+ require 'exception_notifier/rake/version'
data/test/rake_test.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require 'exception_notifier/rake'
3
+
4
+ class RakeTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ ExceptionNotifier::Rake.reset_for_test
8
+ assert !ExceptionNotifier::Rake.configured?
9
+ end
10
+
11
+ def test_configure_only_default_options
12
+ ExceptionNotifier::Rake.configure({})
13
+ assert ExceptionNotifier::Rake.configured?
14
+ assert_equal ExceptionNotifier::Rake.default_notifier_options,
15
+ ExceptionNotifier::Rake.notifier_options
16
+ end
17
+
18
+ def test_configure_custom_options
19
+ some_options = {
20
+ :sender_address => 'foo@example.com',
21
+ :exception_recipients => ['bar@example.com'],
22
+ }
23
+ ExceptionNotifier::Rake.configure({}, some_options)
24
+ assert ExceptionNotifier::Rake.configured?
25
+ assert_equal some_options.merge(ExceptionNotifier::Rake.default_notifier_options),
26
+ ExceptionNotifier::Rake.notifier_options
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification-rake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Nik Haldimann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: exception_notification
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: An extension of the exception_notification gem to support sending mail
47
+ upon failures in Rake tasks
48
+ email:
49
+ - nhaldimann@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.md
57
+ - README.md
58
+ - Rakefile
59
+ - exception_notification-rake.gemspec
60
+ - lib/exception_notifier/rake.rb
61
+ - lib/exception_notifier/rake/rake.rb
62
+ - lib/exception_notifier/rake/rake_patch.rb
63
+ - lib/exception_notifier/rake/version.rb
64
+ - test/rake_test.rb
65
+ homepage: https://github.com/nikhaldi/exception_notification-rake
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>'
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.1
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Sending exception notifications upon Rake task failures
89
+ test_files:
90
+ - test/rake_test.rb
91
+ has_rdoc: