rusen 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,21 @@
1
1
  require 'rusen/settings'
2
2
  require 'rusen/notifier'
3
- #require 'rusen/notification'
4
3
 
5
4
  module Rusen
6
5
 
7
6
  @settings = Settings.new
8
7
  @notifier = Notifier.new(@settings)
9
8
 
9
+ # Returns the global settings for rusen.
10
+ #
11
+ # This settings apply to the notifications sent with Rusen.notify
12
+ #
13
+ # @return [Rusen::Settings] rusen global settings.
10
14
  def self.settings
11
15
  @settings
12
16
  end
13
17
 
18
+ # (see Rusen::Notifier#notify)
14
19
  def self.notify(exception, request = nil, environment = nil, session = nil)
15
20
  @notifier.notify(exception, request, environment, session)
16
21
  end
@@ -6,6 +6,7 @@ module Rusen
6
6
  module Middleware
7
7
 
8
8
  class RusenRack
9
+
9
10
  def initialize(app, settings = {})
10
11
  @app = app
11
12
 
@@ -17,6 +18,7 @@ module Rusen
17
18
  @rusen_settings.sender_address = settings[:sender_address]
18
19
  @rusen_settings.exception_recipients = settings[:exception_recipients]
19
20
  @rusen_settings.smtp_settings = settings[:smtp_settings]
21
+ @rusen_settings.exclude_if = settings[:exclude_if]
20
22
 
21
23
  @notifier = Notifier.new(@rusen_settings)
22
24
  end
@@ -25,13 +27,15 @@ module Rusen
25
27
  begin
26
28
  @app.call(env)
27
29
  rescue Exception => error
28
- request = Rack::Request.new(env)
29
-
30
- @notifier.notify(error, request.GET.merge(request.POST), env, request.session)
30
+ unless @rusen_settings.exclude_if.call(error)
31
+ request = Rack::Request.new(env)
32
+ @notifier.notify(error, request.GET.merge(request.POST), env, request.session)
33
+ end
31
34
 
32
35
  raise
33
36
  end
34
37
  end
38
+
35
39
  end
36
40
 
37
41
  end
@@ -1,5 +1,6 @@
1
1
  module Rusen
2
2
 
3
+ # Class for holding all the information that can be sent in a notification.
3
4
  class Notification
4
5
 
5
6
  attr_reader :exception, :request, :environment, :session
@@ -22,6 +22,12 @@ module Rusen
22
22
  @notifiers << notifier_class.new(@settings)
23
23
  end
24
24
 
25
+ # Sends a notification to the configured outputs.
26
+ #
27
+ # @param [Exception] exception The error.
28
+ # @param [Hash<Object, Object>] request The request params
29
+ # @param [Hash<Object, Object>] environment The environment status.
30
+ # @param [Hash<Object, Object>] session The session status.
25
31
  def notify(exception, request = nil, environment = nil, session = nil)
26
32
  begin
27
33
  notification = Notification.new(exception, request, environment, session)
@@ -32,7 +38,7 @@ module Rusen
32
38
 
33
39
  # We need to ignore all the exceptions thrown by the notifiers.
34
40
  rescue Exception
35
- ERROR("Rusen: Some or all the notifiers failed to sent the notification.")
41
+ warn("Rusen: Some or all the notifiers failed to sent the notification.")
36
42
  end
37
43
  end
38
44
 
@@ -20,9 +20,10 @@ module Rusen
20
20
 
21
21
  Pony.mail(email_options.merge({:body => build_body}))
22
22
 
23
- # We need to ignore all the exceptions thrown by EmailNotifier.notify.
23
+ # We need to ignore all the exceptions thrown by EmailNotifier#notify.
24
24
  rescue Exception => e
25
- ERROR("Rusen: #{e.message} prevented the notification email from being sent.")
25
+ warn("Rusen: #{e.class}: #{e.message} prevented the notification email from being sent.")
26
+ puts e.backtrace
26
27
  end
27
28
  end
28
29
 
@@ -42,9 +42,9 @@ module Rusen
42
42
  print_hash(notification.environment)
43
43
  end
44
44
 
45
- # We need to ignore all the exceptions thrown by IONotifier.notify.
45
+ # We need to ignore all the exceptions thrown by IONotifier#notify.
46
46
  rescue Exception => e
47
- ERROR("Rusen: #{e.message} prevented the io notifier from login the error.")
47
+ warn("Rusen: #{e.message} prevented the io notifier from login the error.")
48
48
  end
49
49
  end
50
50
 
@@ -8,31 +8,71 @@ module Rusen
8
8
  attr_writer :exception_recipients
9
9
  attr_writer :sections
10
10
  attr_writer :smtp_settings
11
+ attr_writer :exclude_if
11
12
 
13
+ # Returns the configured outputs.
14
+ #
15
+ # Default: [:io, :email]
16
+ #
17
+ # @return [Array<Symbol>]
12
18
  def outputs
13
19
  @outputs || [:io, :email]
14
20
  end
15
21
 
22
+ # Returns the notification email prefix.
23
+ #
24
+ # Default: '[Exception] '
25
+ #
26
+ # @return [String]
16
27
  def email_prefix
17
28
  @email_prefix || '[Exception] '
18
29
  end
19
30
 
31
+ # Returns the notification email sender.
32
+ #
33
+ # Default: ''
34
+ #
35
+ # @return [String]
20
36
  def sender_address
21
37
  @sender_address || ''
22
38
  end
23
39
 
40
+ # Returns the notification email recipients.
41
+ #
42
+ # Default: []
43
+ #
44
+ # @return [Array<String>]
24
45
  def exception_recipients
25
46
  @exception_recipients || []
26
47
  end
27
48
 
49
+ # Returns the configured sections.
50
+ #
51
+ # Default: [:backtrace, :request, :session, :environment]
52
+ #
53
+ # @return [Array<Symbol>]
28
54
  def sections
29
55
  @sections || [:backtrace, :request, :session, :environment]
30
56
  end
31
57
 
58
+ # Returns the email smtp settings.
59
+ #
60
+ # Default: {}
61
+ #
62
+ # @return [Hash<Symbol, Object>]
32
63
  def smtp_settings
33
64
  @smtp_settings || {}
34
65
  end
35
66
 
67
+ # Returns whether to send or not the notification for a exception.
68
+ #
69
+ # Default: lambda { |exception| false }
70
+ #
71
+ # @return [Block]
72
+ def exclude_if
73
+ @exclude_if || lambda { |exception| false }
74
+ end
75
+
36
76
  end
37
77
 
38
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: