qmin 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 224035ccd522282d02bb6c6020a115ffe5353d14
4
- data.tar.gz: 9c0f5ac6458d44113c9ecf656c3b5e82120510bc
3
+ metadata.gz: 3ff3f0d1fbde9d321b9724c17b8509ee901767be
4
+ data.tar.gz: 544629dc2e489f2cfab3502fe4057c5e3c44f850
5
5
  SHA512:
6
- metadata.gz: 597fbd9165320d0183e3c7bb523722bdec58f6ccb9fbb189dbc816706f34ae6de13be56c2e499fdc10dbe0b2f531255ae83505d0e4ddf06a64386165a94277e0
7
- data.tar.gz: 2797a8f514bd41aefb36dda45a50a86a8c13a1dcd89a8d4c9ac04ee1d450c36d96de19536539e2a95f6743f3facfc1814b411f5295e0ebb89e5e88881d6626b8
6
+ metadata.gz: 24f64d0830c27904e64e72e015e90ef46941689362065eb4ec4b50ebb70141ad23994ad2b393d4ad5af1c89534fcfae94715f8c471592d3dd35ab4163f34437b
7
+ data.tar.gz: 2fdb9d6d4ca92329e51f72a8e32d3d37f633fc83014ca9fbdc29036e48e76bdc29aabf3ca442b129e87fd2d7b1a74590448829c51d6c2c416fa2a3fa0b070b56
@@ -4,10 +4,11 @@ gemfile: Gemfile.ci
4
4
  before_install:
5
5
  - gem update --system 2.1.11
6
6
  - gem --version
7
+ - gem install bundler
7
8
 
8
9
  rvm:
9
- - ruby-head
10
- - 2.0.0-p0
10
+ - 2.1.0
11
+ - 2.0.0
11
12
  - 1.9.3
12
13
  - 1.9.2
13
14
  - 1.8.7
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in qmin.gemspec
4
4
  gemspec
@@ -1,4 +1,5 @@
1
1
  require 'mail'
2
+ require 'qmin/reporting/mail/mail_builder'
2
3
 
3
4
  module Qmin
4
5
  module Reporting
@@ -50,42 +51,6 @@ module Qmin
50
51
  mail.deliver
51
52
  end
52
53
 
53
-
54
- class MailBuilder
55
- def initialize(exception, mail_to, mail_from)
56
- @exception, @mail_to, @mail_from = exception, mail_to, mail_from
57
- end
58
-
59
- attr_reader :exception, :mail_to, :mail_from
60
-
61
- def build
62
- mail = ::Mail.new
63
-
64
- mail.to mail_to
65
- mail.from mail_from
66
- mail.subject subject
67
- mail.body clean_backtrace.join("\n")
68
-
69
- mail
70
- end
71
-
72
- private
73
-
74
- def subject
75
- "[ERROR] Qmin Report: #{exception.message}"
76
- end
77
-
78
- # copied from exception_notification gem
79
- # http://github.com/smartinez87/exception_notification
80
- def clean_backtrace
81
- if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
82
- Rails.backtrace_cleaner.send(:filter, exception.backtrace)
83
- else
84
- exception.backtrace
85
- end
86
- end
87
- end
88
-
89
54
  end
90
55
  end
91
56
  end
@@ -0,0 +1,38 @@
1
+ module Qmin
2
+ module Reporting
3
+ class MailBuilder
4
+ def initialize(exception, mail_to, mail_from)
5
+ @exception, @mail_to, @mail_from = exception, mail_to, mail_from
6
+ end
7
+
8
+ attr_reader :exception, :mail_to, :mail_from
9
+
10
+ def build
11
+ mail = ::Mail.new
12
+
13
+ mail.to mail_to
14
+ mail.from mail_from
15
+ mail.subject subject
16
+ mail.body clean_backtrace.join("\n")
17
+
18
+ mail
19
+ end
20
+
21
+ private
22
+
23
+ def subject
24
+ "[ERROR] Qmin Report: #{exception.message}"
25
+ end
26
+
27
+ # copied from exception_notification gem
28
+ # http://github.com/smartinez87/exception_notification
29
+ def clean_backtrace
30
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
31
+ Rails.backtrace_cleaner.send(:filter, exception.backtrace)
32
+ else
33
+ exception.backtrace
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,13 +2,21 @@ module Qmin
2
2
  module Resque
3
3
  class BackgroundCallJob
4
4
  def self.perform(*args)
5
- new(*args).perform
5
+ begin
6
+ new(*args).perform
7
+ rescue => e
8
+ ::Qmin::Qmin.current.report(e)
9
+ end
6
10
  end
7
11
 
8
12
  def initialize(klass, method_name, id)
9
- @klass = klass.is_a?(Class) ? klass : klass.constantize
10
- @method_name = method_name
11
- @id = id
13
+ begin
14
+ @klass = klass.is_a?(Class) ? klass : klass.constantize
15
+ @method_name = method_name
16
+ @id = id
17
+ rescue => e
18
+ ::Qmin::Qmin.current.report(e)
19
+ end
12
20
  end
13
21
 
14
22
  def perform
@@ -8,7 +8,11 @@ module Qmin
8
8
 
9
9
  # call method directly
10
10
  def background_call(instance, method_name, *args)
11
- instance.send(::Qmin.method_name_for_instance(instance, method_name), *args)
11
+ begin
12
+ instance.send(::Qmin.method_name_for_instance(instance, method_name), *args)
13
+ rescue => e
14
+ ::Qmin::Qmin.current.report(e)
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -1,3 +1,3 @@
1
1
  module Qmin
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -1,5 +1,5 @@
1
- require_relative '../../spec_helper'
2
- require_relative '../../../lib/qmin'
1
+ require File.expand_path '../../spec_helper', File.dirname(__FILE__)
2
+ require File.expand_path '../../../lib/qmin', File.dirname(__FILE__)
3
3
 
4
4
  describe 'Qmin::Reporting::Inline' do
5
5
  let(:error_producer){ TestClass.new(123) }
@@ -14,7 +14,7 @@ describe 'Qmin::Reporting::Inline' do
14
14
  Qmin::Qmin.default_strategy = Qmin::Strategy::Noop
15
15
  lambda{
16
16
  error_producer.raise_error
17
- }.should_not raise_error(TestClass::CustomError)
17
+ }.should_not raise_error
18
18
  end
19
19
 
20
20
  describe 'resque strategy' do
@@ -25,7 +25,7 @@ describe 'Qmin::Reporting::Inline' do
25
25
  it 'raises no error with resque strategy when enqueueing the job' do
26
26
  lambda{
27
27
  error_producer.raise_error
28
- }.should_not raise_error(TestClass::CustomError)
28
+ }.should_not raise_error
29
29
  end
30
30
 
31
31
  it 'raises error when job is performing' do
@@ -0,0 +1,23 @@
1
+ require File.expand_path '../../../spec_helper', File.dirname(__FILE__)
2
+ require File.expand_path '../../../../lib/qmin', File.dirname(__FILE__)
3
+
4
+ describe 'Qmin::Reporting::MailBuilder' do
5
+
6
+
7
+ let(:message) { 'Exceptional' }
8
+ let(:backtrace) { ['Line 1', 'Line 2'] }
9
+ let(:exception) { err = StandardError.new(message); err.set_backtrace(backtrace); err }
10
+ let(:mail_to) { 'receiver@example.com' }
11
+ let(:mail_from) { 'notifier@example.com' }
12
+
13
+ it 'builds mail' do
14
+ mail = Qmin::Reporting::MailBuilder.new(exception, mail_to, mail_from).build
15
+ mail.should_not be_blank
16
+ mail.should be_kind_of(Mail::Message)
17
+ mail.subject.should match(%r/#{message}$/)
18
+ mail.body.should include(backtrace.join("\n"))
19
+ mail.to.should eql [mail_to]
20
+ mail.from.should eql [mail_from]
21
+ end
22
+
23
+ end
@@ -1,5 +1,5 @@
1
- require_relative '../../spec_helper'
2
- require_relative '../../../lib/qmin'
1
+ require File.expand_path '../../spec_helper', File.dirname(__FILE__)
2
+ require File.expand_path '../../../lib/qmin', File.dirname(__FILE__)
3
3
 
4
4
  describe 'Qmin::Reporting::Mail' do
5
5
 
@@ -16,10 +16,12 @@ describe 'Qmin::Reporting::Mail' do
16
16
 
17
17
  let(:error_producer){ TestClass.new(123) }
18
18
 
19
- it 'raises error for inline strategy' do
19
+ it 'report mail for inline strategy' do
20
20
  lambda{
21
21
  error_producer.raise_error
22
- }.should raise_error(TestClass::CustomError)
22
+ }.should_not raise_error(TestClass::CustomError)
23
+
24
+ Mail::TestMailer.deliveries.should_not be_empty
23
25
  end
24
26
 
25
27
  describe 'resque strategy' do
@@ -30,13 +32,13 @@ describe 'Qmin::Reporting::Mail' do
30
32
  it 'raises no error with resque strategy when enqueuing the job' do
31
33
  lambda{
32
34
  error_producer.raise_error
33
- }.should_not raise_error(TestClass::CustomError)
35
+ }.should_not raise_error
34
36
  end
35
37
 
36
38
  it 'raises error when job is performing' do
37
39
  lambda{
38
40
  Qmin::Resque::BackgroundCallJob.new(TestClass, :raise_error, error_producer.id).perform
39
- }.should_not raise_error(TestClass::CustomError)
41
+ }.should_not raise_error
40
42
 
41
43
  Mail::TestMailer.deliveries.should_not be_empty
42
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - the-architect
@@ -101,6 +101,7 @@ files:
101
101
  - lib/qmin/qmin.rb
102
102
  - lib/qmin/reporting/inline.rb
103
103
  - lib/qmin/reporting/mail.rb
104
+ - lib/qmin/reporting/mail/mail_builder.rb
104
105
  - lib/qmin/reporting/noop.rb
105
106
  - lib/qmin/resque/background_call_job.rb
106
107
  - lib/qmin/resque/base_job.rb
@@ -113,6 +114,7 @@ files:
113
114
  - spec/qmin/core_ext/string_spec.rb
114
115
  - spec/qmin/qmin_spec.rb
115
116
  - spec/qmin/reporting/inline_spec.rb
117
+ - spec/qmin/reporting/mail/mail_builder_spec.rb
116
118
  - spec/qmin/reporting/mail_spec.rb
117
119
  - spec/qmin/resque/background_call_job_spec.rb
118
120
  - spec/qmin/resque/base_job_spec.rb
@@ -149,6 +151,7 @@ test_files:
149
151
  - spec/qmin/core_ext/string_spec.rb
150
152
  - spec/qmin/qmin_spec.rb
151
153
  - spec/qmin/reporting/inline_spec.rb
154
+ - spec/qmin/reporting/mail/mail_builder_spec.rb
152
155
  - spec/qmin/reporting/mail_spec.rb
153
156
  - spec/qmin/resque/background_call_job_spec.rb
154
157
  - spec/qmin/resque/base_job_spec.rb