exceptioner 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -45,7 +45,7 @@ Then require excptioner and use it like:
45
45
  begin
46
46
  # some code which may fail
47
47
  rescue VeryFatalError => e
48
- Exceptioner::Notifier.dispatch(e)
48
+ Exceptioner.notify(e)
49
49
  end
50
50
 
51
51
  == Note on Patches/Pull Requests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/exceptioner.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exceptioner}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Micha\305\202 \305\201omnicki"]
12
- s.date = %q{2010-12-14}
12
+ s.date = %q{2010-12-16}
13
13
  s.description = %q{The most common use is to use Exceptioner as rack middleware and send notifications when an exception occur in you web application. It may be used with Rails, Sinatra or any other rack citizen.
14
14
  Exceptioner may be also used with any ruby code you want. Just configure delivery methods and don't miss any exception.}
15
15
  s.email = %q{michal@lomnicki.com.pl}
@@ -2,13 +2,34 @@ module Exceptioner
2
2
  class Notifier
3
3
 
4
4
  def self.dispatch(exception, options = {})
5
- available_transports = classify_transports(options[:transports] || transports)
6
- available_transports.each do |transport|
7
- transport.deliver(exception, options)
5
+ if dispatch_exception?
6
+ options = determine_options(exception, options.dup)
7
+ determine_transports(options) do |transport|
8
+ transport.deliver(options)
9
+ end
8
10
  end
9
11
  end
10
12
 
11
13
  protected
14
+ def self.determine_options(exception, options)
15
+ if exception.is_a?(Hash)
16
+ options = exception
17
+ exception = nil
18
+ else
19
+ options[:exception] ||= exception
20
+ options[:exception_class] ||= exception.class
21
+ options[:error_message] ||= exception.message
22
+ options[:backtrace] ||= exception.backtrace
23
+ end
24
+ return options
25
+ end
26
+
27
+ def self.determine_transports(options)
28
+ available_transports = classify_transports(options[:transports] || transports)
29
+ available_transports.each { |transport| yield transport }
30
+ available_transports
31
+ end
32
+
12
33
  def self.transports
13
34
  Exceptioner.transports
14
35
  end
@@ -23,5 +44,14 @@ module Exceptioner
23
44
  end
24
45
  end
25
46
 
47
+ def self.config
48
+ Exceptioner
49
+ end
50
+
51
+ def dispatch_exception?
52
+ ! config.development_environments.include?(config.environment_name)
53
+ end
54
+
55
+
26
56
  end
27
57
  end
@@ -7,8 +7,9 @@ module Exceptioner
7
7
  end
8
8
 
9
9
  initializer "exceptioner.use_rails_default" do |app|
10
- Exceptioner.mail.delivery_method = rails_delivery(app)
11
- Exceptioner.mail.delivery_options = rails_delivery_options(app)
10
+ Exceptioner.environment_name ||= Rails.env
11
+ Exceptioner.mail.delivery_method ||= rails_delivery(app)
12
+ Exceptioner.mail.delivery_options ||= rails_delivery_options(app)
12
13
  end
13
14
 
14
15
  protected
@@ -11,7 +11,7 @@ module Exceptioner::Transport
11
11
  class_attribute :subject
12
12
 
13
13
 
14
- def self.deliver(exception, options = {})
14
+ def self.deliver(options = {})
15
15
  raise Exceptioner::ExceptionerError, 'Implement deliver class method in your Exceptioner::Transport::Base subclass'
16
16
  end
17
17
 
@@ -25,11 +25,11 @@ module Exceptioner::Transport
25
25
  }
26
26
  end
27
27
 
28
- def self.prefixed_subject(exception, options)
29
- "#{options[:prefix]}#{exception.message}"
28
+ def self.prefixed_subject(options)
29
+ "#{options[:prefix]}#{options[:error_message]}"
30
30
  end
31
31
 
32
- def self.render(exception, options = {})
32
+ def self.render(options = {})
33
33
  ERB.new(template, nil, '>').result(binding)
34
34
  end
35
35
 
@@ -11,19 +11,20 @@ module Exceptioner::Transport
11
11
 
12
12
  class_attribute :password
13
13
 
14
- def self.deliver(exception, options = {})
15
- connect
16
- messages = prepare_messages(exception, options)
17
- messages.each do |message|
18
- @client.send(message)
14
+ def self.deliver(options = {})
15
+ messages = prepare_messages(options)
16
+ connect do |client|
17
+ messages.each do |message|
18
+ client.send(message)
19
+ end
19
20
  end
20
21
  end
21
22
 
22
23
  protected
23
- def self.prepare_messages(exception, message_options)
24
+ def self.prepare_messages(message_options)
24
25
  options = message_options.dup
25
26
  options = default_options.merge(options)
26
- options[:body] ||= render(exception, message_options)
27
+ options[:body] ||= render(message_options)
27
28
 
28
29
  messages = []
29
30
  Array(options[:recipients]).each do |recipient|
@@ -36,9 +37,10 @@ module Exceptioner::Transport
36
37
 
37
38
  def self.connect
38
39
  jid = ::Jabber::JID.new(self.jabber_id)
39
- @client = ::Jabber::Client.new(jid)
40
- @client.connect
41
- @client.auth(self.password)
40
+ client = ::Jabber::Client.new(jid)
41
+ client.connect
42
+ client.auth(self.password)
43
+ yield client
42
44
  end
43
45
 
44
46
  end
@@ -12,20 +12,11 @@ module Exceptioner::Transport
12
12
 
13
13
  class_attribute :delivery_options
14
14
 
15
- def self.deliver(exception, options = {})
16
- mail = prepare_mail(exception, options)
15
+ def self.deliver(options = {})
16
+ mail = prepare_mail(options)
17
17
  mail.deliver
18
18
  end
19
19
 
20
- def self.determine_mail_options(exception, mail_options)
21
- options = {}
22
- options[:from] ||= options[:sender]
23
- options[:to] ||= options[:recipients]
24
- options[:subject] ||= prefixed_subject(exception, options)
25
- options[:body] ||= render(exception, mail_options)
26
- options.merge!(default_options)
27
- end
28
-
29
20
  protected
30
21
  def self.default_options
31
22
  {
@@ -35,11 +26,11 @@ module Exceptioner::Transport
35
26
  }.merge!(super)
36
27
  end
37
28
 
38
- def self.prepare_mail(exception, mail_options)
29
+ def self.prepare_mail(mail_options)
39
30
  options = mail_options.dup
40
31
  options = default_options.merge(options)
41
- options[:subject] ||= prefixed_subject(exception, options)
42
- options[:body] ||= render(exception, mail_options)
32
+ options[:subject] ||= prefixed_subject(options)
33
+ options[:body] ||= render(mail_options)
43
34
 
44
35
  mail = ::Mail.new(
45
36
  :from => options[:sender],
@@ -1,14 +1,29 @@
1
- Application raised <%= exception.class %>
1
+ <% if options[:exception]%>
2
+ Application raised <%= options[:exception_class].to_s %> <%= options[:error_message] %>
3
+ <% end %>
2
4
  <% if options[:controller] %>
3
5
  from <%= options[:controller].controller_name %>#<%= options[:controller].action_name %>
4
6
  <% end %>.
5
7
 
6
- Message: <%= exception.message.to_s %>.
7
-
8
+ <% if options[:error_message] %>
9
+ <%= Exceptioner::Transport::Helper.title('Error Message') %>
10
+ <%= options[:error_message] %>
11
+ <% end %>
12
+
13
+ <% if options[:backtrace] %>
8
14
  <%= Exceptioner::Transport::Helper.title('Backtrace') %>
9
15
 
10
- <%= exception.backtrace.join("\n\t") %>
16
+ <%= options[:backtrace].join("\n\t") %>
17
+ <% end %>
11
18
 
19
+ <% if options[:parameters] %>
20
+ <% options[:parameters].each_pair do |key, value| %>
21
+ <%= Exceptioner::Transport::Helper.title(key.to_s) %>
22
+
23
+ <%= value.inspect %>
24
+
25
+ <% end %>
26
+ <% end %>
12
27
 
13
28
  <% if options[:env] %>
14
29
  <%= Exceptioner::Transport::Helper.title('Environment') %>
data/lib/exceptioner.rb CHANGED
@@ -24,6 +24,18 @@ module Exceptioner
24
24
  mattr_accessor :dispatch_local_requests
25
25
  @@dispatch_local_requests = false
26
26
 
27
+ # Name of current environment.
28
+ # For rails it would be development, test or production.
29
+ # It's included in exception notification.
30
+ # You can also combine it with development_environments to decide
31
+ # when to handle exceptions by Exceptioner.
32
+ mattr_accessor :environment_name
33
+
34
+ # Define development environment. For these environments exceptions will not
35
+ # be handled by Exceptioner.
36
+ mattr_accessor :development_environments
37
+ @@development_environments = %w[development test cucumber]
38
+
27
39
  def self.setup
28
40
  yield self
29
41
  end
@@ -36,4 +48,8 @@ module Exceptioner
36
48
  Transport::Jabber
37
49
  end
38
50
 
51
+ def self.notify(exception, options = {})
52
+ Notifier.dispatch(exception, options)
53
+ end
54
+
39
55
  end
@@ -4,6 +4,12 @@ Exceptioner.setup do |config|
4
4
  # Define how to deliver information about exception
5
5
  # Available options are: mail, :jabber
6
6
  # config.transports = [:mail]
7
+
8
+ # Environments for which raised exceptions won't be dispatched
9
+ # config.development_environments = %w[development test cucumber]
10
+
11
+ # Name of current environment. For Rails it gets Rails.env by default
12
+ # config.environment_name = Rails.env
7
13
 
8
14
  # ### The section below regards mail transport only ###
9
15
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Micha\xC5\x82 \xC5\x81omnicki"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-14 00:00:00 +01:00
17
+ date: 2010-12-16 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency