me_exceptional 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -51,6 +51,31 @@ In case you also want to customize the mailer, invoke the mailer generator:
51
51
  This creates the directory "/app/mailers/me_exceptional" with the mailer contained.
52
52
 
53
53
 
54
+ == Usage outside of ActionController
55
+
56
+ To use MeExceptional outside ActionController, i.e. in delayed jobs, you must include
57
+ the BasicExtension and specifiy the methods you want to catch exceptions from in the
58
+ class definition.
59
+
60
+
61
+ class Dummy
62
+ include MeExceptional::BasicExtension
63
+
64
+ def some_error
65
+ raise "some error"
66
+ end
67
+
68
+ def another_error
69
+ raise "some error"
70
+ end
71
+
72
+ rescue_mail_from_methods :some_error, :another_error
73
+ end
74
+
75
+ Remember to put the call to rescue_mail_from_methods after the method definitions because
76
+ the methods will be aliased.
77
+
78
+
54
79
  == Outlook
55
80
 
56
81
  * more gem side configuration options
@@ -7,6 +7,12 @@ class MeExceptional::Mailer < ::ActionMailer::Base
7
7
  mail(:from => MeExceptional.mailer_from, :to => MeExceptional.mailer_to, :subject => message)
8
8
  end
9
9
 
10
+ def error_mail(message, params)
11
+ @message, @params = message, params
12
+ subject = "Exception! #{message}"
13
+ mail(:from => MeExceptional.mailer_from, :to => MeExceptional.mailer_to, :subject => subject)
14
+ end
15
+
10
16
  private
11
17
 
12
18
  def get_hostname(ip)
@@ -0,0 +1,17 @@
1
+
2
+ <p style="font-size:12px"><b>Message</b></p>
3
+ <p style="font-size:11px;font-family:Monaco,'Andale Mono',Consolas,'Courier New',monospace">
4
+ <%= @message %>
5
+ </p>
6
+
7
+ <p style="font-size:12px"><b>Time</b></p>
8
+ <p style="font-size:11px;font-family:Monaco,'Andale Mono',Consolas,'Courier New',monospace">
9
+ <%= @params[:timestamp] %>
10
+ </p>
11
+
12
+ <p style="font-size:12px"><b>Complete Backtrace</b></p>
13
+ <p style="font-size:11px;font-family:Monaco,'Andale Mono',Consolas,'Courier New',monospace">
14
+ <%= @params[:backtrace] %>
15
+ </p>
16
+
17
+
@@ -9,14 +9,15 @@ module ActionController
9
9
  def exception_catcher(e)
10
10
  if Rails.env == 'production'
11
11
  # blocking to be sure this gets send!
12
- Emailer.exceptional(e.message,
12
+ MeExceptional::Mailer.exceptional(e.message,
13
13
  :backtrace => e.backtrace.join("\n"),
14
14
  :timestamp => Time.zone.now,
15
15
  :method => request.method,
16
16
  :url => request.url,
17
17
  :params => params.inspect.to_s,
18
18
  :user_agent => request.user_agent,
19
- :client_ip => request.remote_ip,
19
+ #:client_ip => request.remote_ip,
20
+ :client_ip => request.env["HTTP_X_FORWARDED_FOR"].split(',').first,
20
21
  :request_env => request.env.inspect.to_s).deliver
21
22
 
22
23
  end
@@ -5,6 +5,13 @@ require 'action_controller'
5
5
  module MeExceptional
6
6
  class Engine < ::Rails::Engine
7
7
  engine_name :me_exceptional
8
+
9
+ #initialize "me_exceptional.load_app_instance_data" do |app|
10
+ # MeExceptional.setup do |config|
11
+ # config.app_root = app.root
12
+ # end
13
+ #end
14
+
8
15
  end
9
16
  end
10
17
 
@@ -0,0 +1,51 @@
1
+ require 'me_exceptional/engine'
2
+
3
+ module MeExceptional
4
+ module BasicExtension
5
+
6
+ def exception_catcher(e)
7
+ if Rails.env == 'production'
8
+
9
+ m = MeExceptional::Mailer.error_mail(e.message,
10
+ :backtrace => e.backtrace.join("\n"),
11
+ :timestamp => Time.zone.now)
12
+
13
+ # blocking on purpose to be sure this gets sent!
14
+ m.deliver
15
+
16
+ end
17
+ raise e
18
+ end
19
+
20
+ module ClassMethods
21
+ def rescue_mail_from_methods(*methods)
22
+
23
+ methods.each do |method|
24
+ class_eval <<-EOF
25
+ def #{method}_rescuable
26
+ method
27
+ rescue Exception => e
28
+ rescue_with_handler(e)
29
+ end
30
+ alias_method :#{method}, :#{method}_rescuable
31
+ EOF
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ def self.included(base)
38
+ base.extend(ClassMethods)
39
+
40
+ base.instance_eval <<-EOF
41
+ include ActiveSupport::Rescuable
42
+ rescue_from Exception, :with => :exception_catcher
43
+ EOF
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+
@@ -1,3 +1,3 @@
1
1
  module MeExceptional
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails'
2
+ require 'active_support'
2
3
 
3
4
  module MeExceptional
4
5
 
@@ -8,6 +9,7 @@ module MeExceptional
8
9
  mattr_accessor :mailer_to
9
10
  @@mailer_to = nil
10
11
 
12
+ mattr_accessor :app_root
11
13
 
12
14
  def self.setup
13
15
  yield self
@@ -15,9 +17,9 @@ module MeExceptional
15
17
 
16
18
  end
17
19
 
20
+ require 'me_exceptional/extension'
18
21
  require 'me_exceptional/action_controller_extension'
19
22
  require 'me_exceptional/engine'
20
23
 
21
24
 
22
25
 
23
-
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
+ s.add_dependency('activesupport')
22
23
  s.add_dependency('rails')
23
24
  s.add_dependency('geokit')
24
25
 
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: me_exceptional
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 27
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kai Rubarth
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-17 00:00:00 +02:00
19
- default_executable:
18
+ date: 2012-01-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: rails
21
+ name: activesupport
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
@@ -33,7 +32,7 @@ dependencies:
33
32
  type: :runtime
34
33
  version_requirements: *id001
35
34
  - !ruby/object:Gem::Dependency
36
- name: geokit
35
+ name: rails
37
36
  prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
@@ -46,6 +45,20 @@ dependencies:
46
45
  version: "0"
47
46
  type: :runtime
48
47
  version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: geokit
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
49
62
  description: The gem catches exceptions and creates and sends emails with backtrace and other informations.
50
63
  email:
51
64
  - kai@doxter.de
@@ -61,6 +74,7 @@ files:
61
74
  - README.rdoc
62
75
  - Rakefile
63
76
  - app/mailers/me_exceptional/mailer.rb
77
+ - app/views/me_exceptional/mailer/error_mail.html.erb
64
78
  - app/views/me_exceptional/mailer/exceptional.html.erb
65
79
  - lib/generators/me_exceptional/install_generator.rb
66
80
  - lib/generators/me_exceptional/mailers_generator.rb
@@ -70,9 +84,9 @@ files:
70
84
  - lib/me_exceptional.rb
71
85
  - lib/me_exceptional/action_controller_extension.rb
72
86
  - lib/me_exceptional/engine.rb
87
+ - lib/me_exceptional/extension.rb
73
88
  - lib/me_exceptional/version.rb
74
89
  - me_exceptional.gemspec
75
- has_rdoc: true
76
90
  homepage: ""
77
91
  licenses: []
78
92
 
@@ -102,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
116
  requirements: []
103
117
 
104
118
  rubyforge_project: me_exceptional
105
- rubygems_version: 1.3.7
119
+ rubygems_version: 1.8.10
106
120
  signing_key:
107
121
  specification_version: 3
108
122
  summary: notifies you of exceptions by email