rusen 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8007268459cd1078eff76f223cfe229d339bf192
4
- data.tar.gz: fffeb7697f8d8c3cb435ba305212717b653d2542
3
+ metadata.gz: d18a8ccbea67e8e8184a57efb47503278bf4879c
4
+ data.tar.gz: e8d36b8b4b9ab007e9680706adfdfcf806a5506e
5
5
  SHA512:
6
- metadata.gz: f948a54c1cfa25060dd16e7ce9946caa3e63e3b93ad97287bc2fb812bcd343faaa6d87c6ce1c970829cccc185fb3c9ce7abb5ebb42a04268ea327ffbf6a956f0
7
- data.tar.gz: 06c641e4bcdecc748e3ff5a2a3f92fc23deefc8ffab8415aeb0cc3f0d23ea5d0fe1972d1a47b84cb5ab36c16bf15894c5d132e261efccfec61b82b0ce24a36cc
6
+ metadata.gz: fadc00a89b991a47da2460a9dacb3a360b47ca0549d03c9a7f0636e7aaa82e0ba4f4ce07e59100eecaee2f53c94a5d790f02188a9c22ef6e9a49887ec6b34b2e
7
+ data.tar.gz: ab9c7a8bf899b43dcd09cdb2a26e2651578c1c200d7b8475d1629f7a425372119088ccd58d9fa8e4040f23e6dbb3d0dad0fd139c51e65d2fc8d362fea25036cc
@@ -1,23 +1,35 @@
1
- ## HEAD
2
- - Moved presentation to templates by Adrian Gomez
3
- - Improve specs by Adrian Gomez
4
- - Fix default params by Adrian Gomez
5
- - Add log4r support by Adrian Gomez
6
- - Fix gemspec by Peter Boling
7
- - Add LICENSE (MIT) by Peter Boling
8
- - Make VERSION accessible from Ruby (compatible with gem-release) by Peter Boling
9
- - Added Trvis-CI and Coveralls integration by Peter Boling
10
- - Added Rakefile by Peter Boling
11
- - Test against RUby 1.8.7, 1.9.2, 1.9.3, 2.0.0, and jRuby19 by Peter Boling
12
- - Added MailNotifier (for Mail gem) by Peter Boling
13
- - Made mail and pony gems not explicit dependencies; notifiers are loaded dynamically by Peter Boling
14
- - Settings.outputs needs to default to [] in order for the gem to have no default dependencies by Peter Boling
15
-
16
- ## 0.0.2 (2013-01-28)
17
- - Fix when a notificator can't notify by Adrian Gomez
18
- - Added documentation by Adrian Gomez
19
- - Added possibility to skip notification of certain errors by Adrian Gomez
20
-
21
- ## 0.0.1 (2013-01-28)
22
-
23
- First release by Adrian Gomez
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/moove-it/rusen/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/moove-it/rusen/compare/v0.0.2...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Allow sendmail [\#9](https://github.com/moove-it/rusen/issues/9)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Adding a png logo to use on the README.md [\#17](https://github.com/moove-it/rusen/pull/17) ([elpic](https://github.com/elpic))
14
+ - Update CI settings [\#16](https://github.com/moove-it/rusen/pull/16) ([adrian-gomez](https://github.com/adrian-gomez))
15
+ - New Rusen page [\#15](https://github.com/moove-it/rusen/pull/15) ([imNicoSuarez](https://github.com/imNicoSuarez))
16
+ - Allow to omit the optional arguments without errors in Rusen.notify [\#14](https://github.com/moove-it/rusen/pull/14) ([shhavel](https://github.com/shhavel))
17
+ - Change RusenRack to take into account :filter\_parameters option. [\#13](https://github.com/moove-it/rusen/pull/13) ([snmgian](https://github.com/snmgian))
18
+ - Not sending sensitive data on notifications [\#12](https://github.com/moove-it/rusen/pull/12) ([elpic](https://github.com/elpic))
19
+ - Add support for sidekiq. [\#11](https://github.com/moove-it/rusen/pull/11) ([adrian-gomez](https://github.com/adrian-gomez))
20
+ - Add email\_via setting. [\#10](https://github.com/moove-it/rusen/pull/10) ([adrian-gomez](https://github.com/adrian-gomez))
21
+ - Allow sending an instance of Rusen::Settings to the middleware [\#7](https://github.com/moove-it/rusen/pull/7) ([elpic](https://github.com/elpic))
22
+ - Mail notifier [\#6](https://github.com/moove-it/rusen/pull/6) ([pboling](https://github.com/pboling))
23
+ - Just housekeeping. [\#5](https://github.com/moove-it/rusen/pull/5) ([pboling](https://github.com/pboling))
24
+ - Add log4r support. [\#4](https://github.com/moove-it/rusen/pull/4) ([snmgian](https://github.com/snmgian))
25
+ - Fix Rusen::Notifier\#notifty default params. [\#3](https://github.com/moove-it/rusen/pull/3) ([snmgian](https://github.com/snmgian))
26
+ - Fix tests, minor refactoring. [\#2](https://github.com/moove-it/rusen/pull/2) ([snmgian](https://github.com/snmgian))
27
+ - improve some sintax and wording for README [\#1](https://github.com/moove-it/rusen/pull/1) ([ssuttner](https://github.com/ssuttner))
28
+
29
+ ## [v0.0.2](https://github.com/moove-it/rusen/tree/v0.0.2) (2013-01-28)
30
+ [Full Changelog](https://github.com/moove-it/rusen/compare/v0.0.1...v0.0.2)
31
+
32
+ ## [v0.0.1](https://github.com/moove-it/rusen/tree/v0.0.1) (2013-01-28)
33
+
34
+
35
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -1,23 +1,33 @@
1
- [RU]by [S]imple [E]xception [N]otification
2
- ====
3
-
4
- The Ruby Simple Exception Notification (a.k.a Rusen) gem provides a simple way for logging and sending errors in any ruby application.
5
-
6
- The notification includes information about the current request, session, environment and also gives a backtrace of the exception.
7
-
8
- | Project | Rusen |
9
- |------------------------ | ----------------- |
10
- | gem name | rusen |
11
- | license | MIT |
12
- | moldiness | [![Maintainer Status](http://stillmaintained.com/Moove-it/rusen.png)](http://stillmaintained.com/Moove-it/rusen) |
13
- | version | [![Gem Version](https://badge.fury.io/rb/rusen.png)](http://badge.fury.io/rb/rusen) |
14
- | dependencies | [![Dependency Status](https://gemnasium.com/Moove-it/rusen.png)](https://gemnasium.com/Moove-it/rusen) |
15
- | code quality | [![Code Climate](https://codeclimate.com/github/Moove-it/rusen.png)](https://codeclimate.com/github/Moove-it/rusen) |
16
- | continuous integration | [![Build Status](https://secure.travis-ci.org/Moove-it/rusen.png?branch=master)](https://travis-ci.org/Moove-it/rusen) |
17
- | test coverage | [![Coverage Status](https://coveralls.io/repos/Moove-it/rusen/badge.png)](https://coveralls.io/r/Moove-it/rusen) |
18
- | homepage | [https://github.com/Moove-it/rusen][homepage] |
19
- | documentation | [http://rdoc.info/github/Moove-it/rusen/frames][documentation] |
20
- | author | [Adrian Gomez](https://coderbits.com/Moove-it) |
1
+ <p align="center">
2
+ <a href="http://moove-it.github.io/rusen/">
3
+ <img src="https://moove-it.github.io/rusen/images/logo.png" alt="Rusen" />
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://badge.fury.io/rb/rusen">
9
+ <img src="https://badge.fury.io/rb/rusen.png" alt="Gem Version">
10
+ </a>
11
+ <a href="https://codeclimate.com/github/Moove-it/rusen">
12
+ <img src="https://codeclimate.com/github/Moove-it/rusen.png" alt="Code Climate">
13
+ </a>
14
+ <a href="https://travis-ci.org/moove-it/rusen">
15
+ <img src="https://secure.travis-ci.org/moove-it/rusen.png?branch=master" alt="Build Status">
16
+ </a>
17
+ <a href="https://coveralls.io/github/moove-it/rusen?branch=master">
18
+ <img src="https://coveralls.io/repos/moove-it/rusen/badge.svg?branch=master&service=github" alt="Coverage Status">
19
+ </a>
20
+ <a href="https://inch-ci.org/github/moove-it/rusen">
21
+ <img src="https://inch-ci.org/github/moove-it/rusen.svg?branch=master" alt="Documentation Coverage">
22
+ </a>
23
+ <a href="http://www.rubydoc.info/github/moove-it/rusen">
24
+ <img src="https://img.shields.io/badge/yard-docs-blue.svg" alt="Documentation">
25
+ </a>
26
+ </p>
27
+
28
+ The Ruby Simple Exception Notification (a.k.a Rusen) gem provides a simple way for logging and sending errors in any Ruby application.
29
+
30
+ Notifications include information about the current request, session, environment. They also provide a backtrace of the exception.
21
31
 
22
32
  Installation
23
33
  ---
@@ -36,25 +46,25 @@ Usage
36
46
  The easiest way to use it is with global configuration.
37
47
 
38
48
  First you configure Rusen
49
+
39
50
  ```ruby
40
51
  require 'rusen'
41
52
 
42
- Rusen.settings.outputs = [:io, :email]
43
- Rusen.settings.sections = [:backtrace, :request, :session, :environment]
44
- Rusen.settings.email_prefix = '[ERROR] '
45
- Rusen.settings.sender_address = 'some_email@example.com'
46
- Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
53
+ Rusen.settings.sender_address = 'oops@example.org'
54
+ Rusen.settings.exception_recipients = %w(dev_team@example.org)
47
55
  Rusen.settings.smtp_settings = {
48
56
  :address => 'smtp.gmail.com',
49
57
  :port => 587,
50
58
  :domain => 'example.org',
51
59
  :authentication => :plain,
52
- :user_name => 'dev_team@moove-it.com',
60
+ :user_name => 'dev_team@example.org',
53
61
  :password => 'xxxxxxx',
54
62
  :enable_starttls_auto => true
55
63
  }
56
64
  ```
57
- And the you can start sending notifications:
65
+
66
+ And then you can start sending notifications:
67
+
58
68
  ```ruby
59
69
  begin
60
70
  method.call
@@ -62,54 +72,42 @@ rescue Exception => exception
62
72
  Rusen.notify(exception)
63
73
  end
64
74
  ```
65
- This way, if you modify the notifications settings at runtime, every notification sent afterwards will use the new settings.
75
+
76
+ This way, if you modify the notifications settings at runtime, every notification sent afterwards will use the new
77
+ settings.
66
78
 
67
79
  ### With local configuration
68
80
 
69
- This method lets you have more control when notifying. You may want for example to send an email when a particular exception occurs and just print to stdout otherwise.
81
+ This method lets you have more control when notifying. You may want for example to send an email when a particular
82
+ exception occurs and just print to stdout otherwise.
70
83
  To achieve this you can do the following:
84
+
71
85
  ```ruby
72
- @email_settings = Settings.new
73
- @email_settings.outputs = settings[:email]
74
- Rusen.settings.sections = [:backtrace, :request, :session]
75
- @email_settings.email_prefix = '[ERROR] '
76
- @email_settings.sender_address = 'some_email@example.com'
77
- @email_settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
78
- @email_settings.smtp_settings = {
79
- :address => 'smtp.gmail.com',
80
- :port => 587,
81
- :domain => 'example.org',
82
- :authentication => :plain,
83
- :user_name => 'dev_team@moove-it.com',
84
- :password => 'xxxxxxx',
85
- :enable_starttls_auto => true
86
- }
87
-
88
- @email_notifier = Notifier.new(@email_settings)
89
-
90
- @stdout_settings = Settings.new
91
- @stdout_settings.outputs = settings[:io]
92
- Rusen.settings.sections = [:backtrace]
93
-
94
- @stdout_notifier = Notifier.new(@stdout_settings)
86
+ @email_notifier = Rusen::Notifier.new(@email_settings)
87
+
88
+ @stdout_settings = Rusen::Settings.new
89
+ @stdout_settings.outputs = [:backtrace]
90
+
91
+ @stdout_notifier = Rusen::Notifier.new(@stdout_settings)
95
92
  ```
93
+
96
94
  and then:
97
95
  ```ruby
98
96
  begin
99
97
  method.call
100
98
  rescue SmallException => exception
101
99
  @stdout_notifier.notify(exception)
102
- rescue BigException => exception
103
- @email_notifier.notify(exception)
104
100
  end
105
101
  ```
106
102
 
107
103
  Middleware
108
104
  ---
109
- Rusen comes with a rack and rails special (soon to come) middleware for easy usage.
105
+ Rusen comes with a Rack and rails special (soon to come) middleware for easy usage.
110
106
 
111
107
  ### Rack
112
- To use Rusen in any rack application you just have to add the following code somewhere in your app (ex: config/initializers/rusen.rb):
108
+ To use Rusen in any Rack application you just have to add the following code somewhere in your app
109
+ (ex: config/initializers/rusen.rb):
110
+
113
111
  ```ruby
114
112
  require 'rusen/middleware/rusen_rack'
115
113
 
@@ -117,56 +115,71 @@ use Rusen::Middleware::RusenRack,
117
115
  :outputs => [:io, :email],
118
116
  :sections => [:backtrace, :request, :session, :environment],
119
117
  :email_prefix => '[ERROR] ',
120
- :sender_address => 'some_email@example.com',
121
- :exception_recipients => %w(dev_team@example.com test_team@example.com),
118
+ :sender_address => 'oops@example.org',
119
+ :exception_recipients => %w(dev_team@example.org),
122
120
  :smtp_settings => {
123
- :address => 'smtp.gmail.com',
124
- :port => 587,
125
- :domain => 'example.org',
126
- :authentication => :plain,
127
- :user_name => 'dev_team@moove-it.com',
128
- :password => 'xxxxxxx',
129
- :enable_starttls_auto => true
130
- }
121
+ :address => 'smtp.gmail.com',
122
+ :port => 587,
123
+ :domain => 'example.org',
124
+ :authentication => :plain,
125
+ :user_name => 'dev_team@example.org',
126
+ :password => 'xxxxxxx',
127
+ :enable_starttls_auto => true
128
+ }
131
129
  ```
130
+
132
131
  This will capture any unhandled exception, send an email and write a trace in stdout.
133
132
 
134
133
  Settings
135
134
  ---
135
+
136
136
  ### Outputs
137
- Currently supported outputs are :io, :lo4r, :pony and :mail. More outputs are easy to add so you can customize Rusen to your needs.
138
137
 
139
- Note: :io will only print to stdout for the time being, but there are plans to extend it to anything that Ruby::IO supports.
138
+ Currently supported outputs are :io, :lo4r, :pony and :mail. More outputs are easy to add so you can customize Rusen to
139
+ your needs.
140
+
141
+ Note: :io will only print to stdout for the time being, but there are plans to extend it to anything that Ruby::IO
142
+ supports.
140
143
 
141
144
  Pony, lo4r and Mail outputs require additional gems to work.
142
145
 
143
- To use pony add this to your Gemfile:
146
+ To use Pony add this to your Gemfile:
147
+
144
148
  ```ruby
145
149
  gem 'pony'
146
150
  ```
147
151
 
148
- To use mail add this to your Gemfile:
152
+ To use mail, add this to your Gemfile:
153
+
149
154
  ```ruby
150
155
  gem 'mail'
151
156
  ```
152
157
 
153
- To use log4r add this to your Gemfile:
158
+ To use log4r, add this to your Gemfile:
159
+
154
160
  ```ruby
155
161
  gem 'log4r'
156
162
  ```
157
163
 
158
164
  ### Sections
165
+
159
166
  You can choose the output sections simply by setting the appropriate values in the configuration.
160
167
 
161
168
  ### Exclude if
169
+
162
170
  Here you can pass a block that will receive the error. If the block returns false, then the error will be notified.
163
171
 
164
172
  ### Email settings
165
- All the email settings are self explanatory, but you can contact me if any of them needs clarification.
173
+
174
+ All the email settings are self explanatory, but you can contact hello+rusen@moove-it.com if any of them needs clarification.
175
+
176
+ If you are running Rusen inside **Rails** and you have configured smtp_settings for your app
177
+ Rusen will use that settings by default.
166
178
 
167
179
  ### Log4r settings
180
+
168
181
  * logger_name _(required)_: Logger used for logging errors.
169
- * log4r_config_file _(optional)_: YAML file that contains Log4r configuration. Rusen will load that file when given.
182
+ * log4r_config_file _(optional)_: YAML file that contains Log4r configuration.
170
183
 
171
184
  Sample of Log4r configuration file contents:
172
185
 
@@ -191,22 +204,26 @@ log4r_config:
191
204
 
192
205
  Sidekiq
193
206
  ---
207
+
194
208
  Rusen comes with sidekiq integration builtin to use just add this to your sidekiq initializer:
209
+
195
210
  ```ruby
196
211
  require 'rusen/sidekiq'
197
212
  ```
198
- You can configure it with the global rusen configuration, ex:
213
+
214
+ You can configure it with the global Rusen configuration, ex:
215
+
199
216
  ```ruby
200
217
  require 'rusen/sidekiq'
201
218
 
202
- Rusen.settings.sender_address = 'some_email@example.com'
203
- Rusen.settings.exception_recipients = %w(dev_team@example.com test_team@example.com)
219
+ Rusen.settings.sender_address = 'oops@example.org'
220
+ Rusen.settings.exception_recipients = %w(dev_team@example.org)
204
221
  Rusen.settings.smtp_settings = {
205
222
  :address => 'smtp.gmail.com',
206
223
  :port => 587,
207
224
  :domain => 'example.org',
208
225
  :authentication => :plain,
209
- :user_name => 'dev_team@moove-it.com',
226
+ :user_name => 'dev_team@example.org',
210
227
  :password => 'xxxxxxx',
211
228
  :enable_starttls_auto => true
212
229
  }
@@ -214,17 +231,9 @@ Rusen.settings.smtp_settings = {
214
231
 
215
232
  Rusen supports versions ~> 2 and ~> 3 of sidekiq.
216
233
 
217
- Extending to more outputs
218
- ---
219
- Soon to come!
220
-
221
- ## Authors
222
-
223
- Adrian Gomez is the author of the code, and current maintainer.
224
-
225
234
  ## Contributors
226
235
 
227
- See the [Network View](https://github.com/Moove-it/rusen/network) and the [CHANGELOG](https://github.com/Moove-it/rusen/blob/master/CHANGELOG.md)
236
+ See the [Network View](https://github.com/moove-it/rusen/network) and the [CHANGELOG](https://github.com/moove-it/rusen/blob/master/CHANGELOG.md)
228
237
 
229
238
  ## Contributing
230
239
 
@@ -232,31 +241,12 @@ See the [Network View](https://github.com/Moove-it/rusen/network) and the [CHANG
232
241
  2. Create your feature branch (`git checkout -b my-new-feature`)
233
242
  3. Commit your changes (`git commit -am 'Added some feature'`)
234
243
  4. Push to the branch (`git push origin my-new-feature`)
235
- 5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
236
- 6. Create new Pull Request
237
-
238
- ## Versioning
239
-
240
- This library aims to adhere to [Semantic Versioning 2.0.0][semver].
241
- Violations of this scheme should be reported as bugs. Specifically,
242
- if a minor or patch version is released that breaks backward
243
- compatibility, a new version should be immediately released that
244
- restores compatibility. Breaking changes to the public API will
245
- only be introduced with new major versions.
246
-
247
- As a result of this policy, you can (and should) specify a
248
- dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
249
-
250
- For example:
251
-
252
- spec.add_dependency 'rusen', '~> 0.0.2'
244
+ 5. Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
245
+ 6. Create a new Pull Request
253
246
 
254
247
  ## Legal
255
248
 
256
- * MIT License - See LICENSE file in this project
257
- * Copyright (c) 2013 Adrian Gomez
249
+ Rusen is released under the [MIT License](http://opensource.org/licenses/MIT).
258
250
 
259
- [semver]: http://semver.org/
260
- [pvc]: http://docs.rubygems.org/read/chapter/16#page74
261
- [documentation]: http://rdoc.info/github/Moove-it/rusen/frames
262
- [homepage]: https://github.com/Moove-it/rusen
251
+ [documentation]: http://http://www.rubydoc.info/github/moove-it/rusen
252
+ [homepage]: http://moove-it.github.io/rusen/
data/Rakefile CHANGED
@@ -51,15 +51,4 @@ namespace :test do
51
51
  end
52
52
  end
53
53
 
54
- #require File.expand_path('../lib/rusen/version', __FILE__)
55
- #require 'rdoc'
56
- #require 'rdoc/task'
57
- #RDoc::Task.new do |rdoc|
58
- # rdoc.rdoc_dir = 'rdoc'
59
- # rdoc.title = "Rusen #{Rusen::VERSION}"
60
- # rdoc.options << '--line-numbers'
61
- # rdoc.rdoc_files.include('README*')
62
- # rdoc.rdoc_files.include('lib/**/*.rb')
63
- #end
64
-
65
- Bundler::GemHelper.install_tasks
54
+ Bundler::GemHelper.install_tasks
@@ -2,6 +2,10 @@ require 'rusen/version'
2
2
  require 'rusen/settings'
3
3
  require 'rusen/notifier'
4
4
 
5
+ # Rusen is a util to help you with the tracking on the
6
+ # application exceptions, this could be used on any
7
+ # ruby project. The exceptions can be sent to different
8
+ # outputs depending on your apps requirements.
5
9
  module Rusen
6
10
 
7
11
  @settings = Settings.new
@@ -16,7 +20,7 @@ module Rusen
16
20
  end
17
21
 
18
22
  # (see Rusen::Notifier#notify)
19
- def self.notify(exception, request = nil, environment = nil, session = nil)
23
+ def self.notify(exception, request = {}, environment = {}, session = {})
20
24
  notifier.notify(exception, request, environment, session)
21
25
  end
22
26
 
@@ -24,4 +28,4 @@ module Rusen
24
28
  @notifier || Notifier.new(@settings)
25
29
  end
26
30
 
27
- end
31
+ end
@@ -11,28 +11,22 @@ module Rusen
11
11
  @app = app
12
12
 
13
13
  if settings.is_a?(::Rusen::Settings)
14
- @rusen_settings = settings
15
- else
16
- @rusen_settings = Settings.new
17
-
18
- @rusen_settings.outputs = settings[:outputs]
19
- @rusen_settings.sections = settings[:sections]
20
- @rusen_settings.filter_parameters = settings[:filter_parameters]
21
- @rusen_settings.email_prefix = settings[:email_prefix]
22
- @rusen_settings.sender_address = settings[:sender_address]
23
- @rusen_settings.exception_recipients = settings[:exception_recipients]
24
- @rusen_settings.smtp_settings = settings[:smtp_settings]
25
- @rusen_settings.exclude_if = settings[:exclude_if]
14
+ @settings = settings
15
+ elsif settings.is_a?(Hash)
16
+ @settings = ::Rusen::Settings.new(settings)
26
17
  end
27
18
 
28
- @notifier = Notifier.new(@rusen_settings)
19
+ @notifier = ::Rusen::Notifier.new(@settings) if @settings
29
20
  end
30
21
 
31
22
  def call(env)
32
23
  begin
33
24
  @app.call(env)
34
25
  rescue Exception => error
35
- unless @rusen_settings.exclude_if.call(error)
26
+ @notifier ||= Rusen.notifier
27
+ @settings ||= Rusen.settings
28
+
29
+ if @settings && !@settings.exclude_if.call(error)
36
30
  request = Rack::Request.new(env)
37
31
  @notifier.notify(error, request.GET.merge(request.POST), env, request.session)
38
32
  end
@@ -3,10 +3,23 @@ require 'sidekiq'
3
3
 
4
4
  module Rusen
5
5
  module Middleware
6
+
7
+ # Intersect exceptions that happens on inside
8
+ # sidekiq workers. If an exception occurred
9
+ # on a worker Rusen will notify about that
10
+ # exception and will raised up.
6
11
  class RusenSidekiq
7
12
  include Sidekiq::Util
8
13
 
9
- def call(worker, msg, queue, &block)
14
+ # Just yield the block and rescue from any
15
+ # exception that occurred on the call to
16
+ # the worker, and notify about that
17
+ # exception.
18
+ #
19
+ # @raise [Exception] if an exception occurred
20
+ # that exception was notified and raised
21
+ # again to allow the retry to happen.
22
+ def call(_, _, _, &block)
10
23
  yield
11
24
  rescue => error
12
25
  Rusen.notify(error)
@@ -16,4 +29,4 @@ module Rusen
16
29
 
17
30
  end
18
31
  end
19
- end
32
+ end
@@ -46,10 +46,10 @@ module Rusen
46
46
 
47
47
  # We need to ignore all the exceptions thrown by the notifiers.
48
48
  rescue Exception
49
- warn("Rusen: Some or all the notifiers failed to sent the notification.")
49
+ warn('Rusen: Some or all the notifiers failed to sent the notification.')
50
50
  end
51
51
  end
52
52
 
53
53
  end
54
54
 
55
- end
55
+ end
@@ -8,22 +8,27 @@ module Rusen
8
8
  :log4r => :Log4rNotifier,
9
9
  }
10
10
 
11
- def self.load_klass(ident, klass_sym = nil)
12
- klass_sym ||= NOTIFIERS[ident]
13
- if klass_sym
14
- require "rusen/notifiers/#{ident}_notifier" unless Notifiers.constants.include?(klass_sym)
15
- Notifiers.const_get(klass_sym)
16
- else
17
- return nil
11
+ class << self
12
+
13
+ def load_klass(ident, klass_sym = nil)
14
+ klass_sym ||= NOTIFIERS[ident]
15
+ if klass_sym
16
+ require "rusen/notifiers/#{ident}_notifier" unless Notifiers.constants.include?(klass_sym)
17
+ Notifiers.const_get(klass_sym)
18
+ else
19
+ return nil
20
+ end
18
21
  end
19
- end
20
22
 
21
- def self.check_deprecation(ident)
22
- if ident == :email
23
- warn ':email is a deprecated output type. :pony replaces :email. A new alternative is :mail (mail gem).'
24
- return :pony
23
+ def check_deprecation(ident)
24
+ if ident == :email
25
+ warn ':email is a deprecated output type. :pony replaces :email. A new alternative is :mail (mail gem).'
26
+ return :pony
27
+ end
28
+ return ident
25
29
  end
26
- return ident
30
+
27
31
  end
32
+
28
33
  end
29
34
  end
@@ -4,16 +4,41 @@ require_relative '../utils/parameter_filter'
4
4
  module Rusen
5
5
  module Notifiers
6
6
 
7
+ # This class define all the base behaviour of all notifiers,
8
+ # for creating new notifiers this class should be
9
+ # extended.
7
10
  class BaseNotifier
8
11
 
9
- def self.identification_symbol
10
- :base_notifier
12
+ class << self
13
+
14
+ # Symbol that represent the notifier, all subclasses must
15
+ # override this method to be correctly identified.
16
+ #
17
+ # @return [Symbol]
18
+ def identification_symbol
19
+ :base_notifier
20
+ end
21
+
11
22
  end
12
23
 
24
+ # Create a new instance of a Notifier.
25
+ #
26
+ # @param [Rusen::Setting] settings the settings that will be
27
+ # used to notify, depending on this configuration is where
28
+ # the exception will be notified.
29
+ #
30
+ # @return [Rusen::Notifier::BaseNotifier]
13
31
  def initialize(settings)
14
32
  @settings = settings.dup
15
33
  end
16
34
 
35
+ # Given the exception returns all the sessions that will be
36
+ # included on the notification.
37
+ #
38
+ # @param [Rusen::Notification] notification information that
39
+ # will be notified.
40
+ #
41
+ # @return [Hash<String, Object>]
17
42
  def get_sessions(notification)
18
43
  result = {}
19
44
 
@@ -25,6 +50,12 @@ module Rusen
25
50
  result
26
51
  end
27
52
 
53
+ # Some times when we try to notify exceptions an error could
54
+ # happen, for example if someone forgot to config the smtp
55
+ # settings, if that happens and an exception is raised then
56
+ # a warn is logged on the console saying the problem.
57
+ #
58
+ # @param [Exception] exception the error that was raised.
28
59
  def handle_notification_exception(exception)
29
60
  name = self.class.identification_symbol.to_s
30
61
 
@@ -33,6 +64,7 @@ module Rusen
33
64
 
34
65
  private
35
66
 
67
+ # @private
36
68
  def include_session(sessions, session, session_key)
37
69
  @settings.sections
38
70
 
@@ -43,6 +75,7 @@ module Rusen
43
75
  end
44
76
  end
45
77
 
78
+ # @private
46
79
  def parameter_filter
47
80
  @parameter_filter ||= ParameterFilter.new(@settings.filter_parameters)
48
81
  end
@@ -50,4 +83,4 @@ module Rusen
50
83
  end
51
84
 
52
85
  end
53
- end
86
+ end
@@ -16,13 +16,26 @@ module Rusen
16
16
  attr_accessor :logger_name
17
17
  attr_accessor :log4r_config_file
18
18
 
19
+ # Create a new Settings object using the given
20
+ # attributes.
21
+ #
22
+ # @param [Hash<String, Object>] attrs a hash with the
23
+ # options used to create a setting object.
24
+ def initialize(attrs = {})
25
+ (attrs || {}).each do |attr_name, value|
26
+ method_name = "#{attr_name}=".to_sym
27
+
28
+ self.send(method_name, value) if self.respond_to?(method_name)
29
+ end
30
+ end
31
+
19
32
  # Returns the configured outputs.
20
33
  #
21
- # Default: []
34
+ # Default: [:mail]
22
35
  #
23
36
  # @return [Array<Symbol>]
24
37
  def outputs
25
- @outputs || []
38
+ @outputs || [:mail]
26
39
  end
27
40
 
28
41
  # Returns the notification email prefix.
@@ -70,13 +83,17 @@ module Rusen
70
83
  @sections || [:backtrace, :request, :session, :environment]
71
84
  end
72
85
 
73
- # Returns the email smtp settings.
74
- #
75
- # Default: {}
86
+ # Returns the email smtp settings, if Rusen is included on a Rails
87
+ # application the smtp settings for the application is returned,
88
+ # otherwise an empty has is returned.
76
89
  #
77
90
  # @return [Hash<Symbol, Object>]
78
91
  def smtp_settings
79
- @smtp_settings || {}
92
+ if @smtp_settings
93
+ @smtp_settings
94
+ else
95
+ (defined?(Rails) && Rails.configuration.action_mailer.smtp_settings) || {}
96
+ end
80
97
  end
81
98
 
82
99
  # Returns whether to send or not the notification for a exception.
@@ -102,7 +119,7 @@ module Rusen
102
119
  if @filter_parameters
103
120
  @filter_parameters || []
104
121
  else
105
- defined?(Rails) && Rails.application.config.filter_parameters
122
+ defined?(Rails) && Rails.configuration.filter_parameters
106
123
  end
107
124
  end
108
125
 
@@ -1,3 +1,3 @@
1
1
  module Rusen
2
- VERSION='0.0.4'
2
+ VERSION = '0.1.0'
3
3
  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.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gomez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-14 00:00:00.000000000 Z
12
+ date: 2015-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 2.2.2
222
+ rubygems_version: 2.4.5
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: RUby Simple Exception Notification