exception_master 0.1.2 → 0.1.3

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: ef130c07fdb6f11f868b1a4488899c81e4db2814
4
- data.tar.gz: 815d9f0f0dac2fa331e767060e54fb7283420441
3
+ metadata.gz: df71a06b4915e4727d79d7293b3ad072c2f6e281
4
+ data.tar.gz: 4da6560d9c6ed77dbbbd683cff971e1ca2ed6208
5
5
  SHA512:
6
- metadata.gz: 440f37f288579550e7756f555bae59613ae9acf45b1dce7bbc1e4f4cadf03dd5ae367d5a307bb595487ebf840ac3e53c7940260ba4ea857fac13b338c3709ffa
7
- data.tar.gz: 5eee60d99a220ddd457ab80045949b01f9a8100be79ae997abcde6eda9ea11ee87b4584490ab897b2e1440be4af60e5ae65c4bf11ddece850f50641a85a8f36a
6
+ metadata.gz: 79f725c5e50e0d3a24a07a125c0c9a3535eb95b31791aa783dc3fc831dde8ad5eba87178fafc3d9141621bbed1a58bde6348e9ef503a7aa63b16189d55a750e4
7
+ data.tar.gz: 7594d13c046466dd362c002fecccd59863ad76bc5fa09e156e174b39ed1b1b3faa0bd5347e6553dccc6d0cc1175daee0fbfcc885357346a704c65795b7165716
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: exception_master 0.1.3 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "exception_master"
8
- s.version = "0.1.2"
9
+ s.version = "0.1.3"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Roman Snitko"]
12
- s.date = "2014-03-20"
14
+ s.date = "2014-07-25"
13
15
  s.description = "Kinda like ExceptionNotification, but for Ruby, not just for Rails"
14
16
  s.email = "roman.snitko@gmail.com"
15
17
  s.extra_rdoc_files = [
@@ -32,8 +34,7 @@ Gem::Specification.new do |s|
32
34
  ]
33
35
  s.homepage = "http://github.com/snitko/exception_master"
34
36
  s.licenses = ["MIT"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = "2.0.3"
37
+ s.rubygems_version = "2.2.2"
37
38
  s.summary = "Simple [email] exception notifications for Ruby programs"
38
39
 
39
40
  if s.respond_to? :specification_version then
@@ -5,12 +5,14 @@ class ExceptionMaster
5
5
 
6
6
  attr_reader :email_config
7
7
 
8
- def initialize(raise_error: true, deliver_email: true, email_config: {})
8
+ def initialize(raise_error: true, deliver_email: true, email_config: {}, environment: 'development', send_when_environment_is: ['production', 'staging'])
9
9
 
10
10
  @email_config = { via: :sendmail, from: 'exception-master@localhost', subject: 'Error' }
11
11
  @email_config.merge!(email_config)
12
12
  @raise_error = raise_error
13
13
  @deliver_email = deliver_email
14
+ @environment = environment
15
+ @send_when_environment_is = send_when_environment_is
14
16
 
15
17
  if @email_config[:to].nil?
16
18
  raise "Please specify email addresses of email recipients using :to key in email_config attr (value should be array)"
@@ -22,11 +24,19 @@ class ExceptionMaster
22
24
  yield
23
25
  rescue Exception => e
24
26
  deliver_exception(e) if @deliver_email
25
- raise(e) and exit if @raise_error
27
+ if @raise_error
28
+ raise(e) and exit
29
+ elsif @environment == 'development'
30
+ puts "\n\nException raised: " + e.inspect
31
+ puts "\nTraceback:\n"
32
+ e.backtrace.each { |line| puts " " + line }
33
+ end
26
34
  end
27
35
 
28
36
  def deliver_exception(e)
29
- Pony.mail(@email_config.merge({html_body: error_to_html(e)}))
37
+ if @send_when_environment_is.include?(@environment)
38
+ Pony.mail(@email_config.merge({html_body: error_to_html(e)}))
39
+ end
30
40
  end
31
41
 
32
42
 
@@ -3,24 +3,28 @@ require_relative '../lib/exception_master'
3
3
  describe ExceptionMaster do
4
4
 
5
5
  it "writes Pony settings" do
6
- em = ExceptionMaster.new(email_config: {via: :smtp, to: 'exception-master-receiver@localhost'})
6
+ em = ExceptionMaster.new(environment: 'production', email_config: {via: :smtp, to: 'exception-master-receiver@localhost'})
7
7
  em.email_config[:via].should == :smtp
8
8
  end
9
9
 
10
10
  it "sends en email on error" do
11
11
  Pony.should_receive(:mail).once
12
- ExceptionMaster.new(raise_error: false, email_config: {to: 'exception-master-receiver@localhost'}).watch { 1/0 }
12
+ ExceptionMaster.new(environment: 'production', raise_error: false, email_config: {to: 'exception-master-receiver@localhost'}).watch { 1/0 }
13
13
  end
14
14
 
15
15
  it "raises error after sending an email" do
16
16
  Pony.stub(:mail)
17
- expect { ExceptionMaster.new(raise_error: true, email_settings: { to: 'exception-master-receiver@localhost'}).watch { 1/0 } }.to raise_exception
17
+ expect { ExceptionMaster.new(environment: 'production', raise_error: true, email_settings: { to: 'exception-master-receiver@localhost'}).watch { 1/0 } }.to raise_exception
18
18
  end
19
19
 
20
20
  it "doesn't deliver when deliver_email flag is set to false" do
21
21
  Pony.should_receive(:mail).exactly(0).times
22
- expect { ExceptionMaster.new(raise_error: true, deliver_email: false, email_settings: { to: 'exception-master-receiver@localhost'}).watch { 1/0 } }.to raise_exception
22
+ expect { ExceptionMaster.new(environment: 'production', raise_error: true, deliver_email: false, email_settings: { to: 'exception-master-receiver@localhost'}).watch { 1/0 } }.to raise_exception
23
+ end
23
24
 
25
+ it "doesn't deliver emails when the environment is not in the send_when_environment_is list" do
26
+ Pony.should_receive(:mail).exactly(0).times
27
+ expect { ExceptionMaster.new(environment: 'development', raise_error: true, deliver_email: false, email_settings: { to: 'exception-master-receiver@localhost'}).watch { 1/0 } }.to raise_exception
24
28
  end
25
29
 
26
30
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pony
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jeweler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.0.1
55
55
  description: Kinda like ExceptionNotification, but for Ruby, not just for Rails
@@ -60,8 +60,8 @@ extra_rdoc_files:
60
60
  - LICENSE.txt
61
61
  - README.md
62
62
  files:
63
- - .document
64
- - .rspec
63
+ - ".document"
64
+ - ".rspec"
65
65
  - Gemfile
66
66
  - Gemfile.lock
67
67
  - LICENSE.txt
@@ -82,17 +82,17 @@ require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.2.2
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Simple [email] exception notifications for Ruby programs