exception-alarm 0.1.0

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.
data/.gitignore ADDED
@@ -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
+ .rbenv-version
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Exception Alarm 0.1.0 (April 6, 2012)
4
+
5
+ * First public release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception-alarm.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexey Vakhov
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.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Exception Alarm
2
+
3
+ This gem refactored clone of exception notifier plugin.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ``` ruby
10
+ gem 'exception-alarm'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Add to ApplicationController before filter
22
+
23
+ ``` ruby
24
+ class ApplicationController < ActionController::Base
25
+ before_filter do
26
+ ExceptionAlarm::Notifier.sender = "project-name@example.com"
27
+ ExceptionAlarm::Notifier.prefix = '[ERROR-project-name]'
28
+ ExceptionAlarm::Notifier.recipients = %w[vakhov@gmail.com]
29
+ end
30
+
31
+ # ...
32
+ end
33
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ <%= raw @exception.message %>
2
+ <%= raw @exception.backtrace.first %>
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/exception_alarm/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexey Vakhov"]
6
+ gem.email = ["vakhov@gmail.com"]
7
+ gem.description = %q{Send email on exception}
8
+ gem.summary = %q{Rails exception alarm like exception notifier}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "exception-alarm"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ExceptionAlarm::VERSION
17
+
18
+ gem.add_dependency "rails", '~> 3.1'
19
+ end
@@ -0,0 +1,4 @@
1
+ require "exception_alarm/version"
2
+ require "exception_alarm/engine"
3
+ require "exception_alarm/notifier"
4
+ require "exception_alarm/middleware"
@@ -0,0 +1,10 @@
1
+ module ExceptionAlarm
2
+ class Engine < Rails::Engine
3
+ config.exception_alarm = ActiveSupport::OrderedOptions.new
4
+ config.exception_alarm.enable = Rails.env.production?
5
+
6
+ initializer 'exception_alarm' do |app|
7
+ app.config.middleware.use ::ExceptionAlarm::Middleware
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ module ExceptionAlarm
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ rescue Exception => exception
10
+ if Rails.application.config.exception_alarm.enable && !ignore_exceptions.include?(exception.class.to_s) && Notifier.recipients.present?
11
+ Notifier.alarm(env, exception).deliver
12
+ end
13
+
14
+ raise exception
15
+ end
16
+
17
+ protected
18
+ def ignore_exceptions
19
+ %w[ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module ExceptionAlarm
2
+ class Notifier < ActionMailer::Base
3
+ cattr_accessor :prefix
4
+ cattr_accessor :sender
5
+ cattr_accessor :recipients
6
+ self.prefix = '[ERROR]'
7
+ self.sender = 'exception@example.com'
8
+ self.recipients = []
9
+
10
+ def alarm(env, exception)
11
+ @env = env
12
+ @exception = exception
13
+
14
+ mail(
15
+ from: self.class.sender,
16
+ to: self.class.recipients,
17
+ subject: "#{self.class.prefix} (#{@exception.class}) #{@exception.message.inspect}"
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module ExceptionAlarm
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception-alarm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Vakhov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &76730070 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *76730070
25
+ description: Send email on exception
26
+ email:
27
+ - vakhov@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - CHANGELOG.md
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/views/exception_alarm/notifier/alarm.txt.erb
39
+ - exception-alarm.gemspec
40
+ - lib/exception-alarm.rb
41
+ - lib/exception_alarm/engine.rb
42
+ - lib/exception_alarm/middleware.rb
43
+ - lib/exception_alarm/notifier.rb
44
+ - lib/exception_alarm/version.rb
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: -455781487
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ segments:
67
+ - 0
68
+ hash: -455781487
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.11
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Rails exception alarm like exception notifier
75
+ test_files: []