safely 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/safely/config.rb CHANGED
@@ -7,7 +7,8 @@ module Safely
7
7
  def initialize
8
8
  @strategies = [
9
9
  Safely::Strategy::Hoptoad,
10
- Safely::Strategy::Mail
10
+ Safely::Strategy::Mail,
11
+ Safely::Strategy::Log
11
12
  ]
12
13
  end
13
14
 
@@ -0,0 +1,30 @@
1
+ module Safely
2
+ module Strategy
3
+ class Log
4
+
5
+ class << self
6
+
7
+ # Logger to use
8
+ attr_accessor :logger
9
+
10
+ # Flush logger
11
+ attr_accessor :flush
12
+
13
+ def load!
14
+ @flush ||= false
15
+ end
16
+
17
+ def report!( exception )
18
+ return if self.logger.nil?
19
+
20
+ self.logger.error("[SAFELY] Type: #{exception.class.name}")
21
+ self.logger.error("[SAFELY] Message: #{exception.message}")
22
+ self.logger.error("[SAFELY] Backtrace: #{exception.backtrace.join("\n ")}")
23
+
24
+ self.logger.flush if self.logger.respond_to?(:flush) && self.flush
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -1,6 +1,7 @@
1
1
  module Safely
2
2
  module Strategy
3
3
  autoload :Hoptoad, 'safely/strategy/hoptoad'
4
+ autoload :Log, 'safely/strategy/log'
4
5
  autoload :Mail, 'safely/strategy/mail'
5
6
  end
6
7
  end
data/lib/safely.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift File.expand_path('../', __FILE__)
2
2
 
3
3
  module Safely
4
4
 
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  autoload :Config, 'safely/config'
8
8
  autoload :Mixin, 'safely/mixin'
@@ -23,13 +23,13 @@ module Safely
23
23
  end
24
24
 
25
25
  def load_strategies!
26
- @config.strategies.each { |s| s.load! }
26
+ config.strategies.each { |s| s.load! }
27
27
  end
28
28
 
29
29
  def report!( exception )
30
30
  load_strategies! if @config.nil?
31
31
 
32
- @config.strategies.each { |s| s.report! exception }
32
+ config.strategies.each { |s| s.report! exception }
33
33
  end
34
34
 
35
35
  private
data/safely.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{safely}
8
- s.version = "0.1.0pre"
8
+ s.version = "0.2.0"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenneth Kalmer"]
12
- s.date = %q{2011-04-14}
12
+ s.date = %q{2011-05-07}
13
13
  s.description = %q{Safely run your code in a loving error reporting embrace}
14
14
  s.email = %q{kenneth.kalmer@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ "CHANGES",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -28,10 +29,18 @@ Gem::Specification.new do |s|
28
29
  "lib/safely.rb",
29
30
  "lib/safely/config.rb",
30
31
  "lib/safely/mixin.rb",
32
+ "lib/safely/strategy.rb",
33
+ "lib/safely/strategy/hoptoad.rb",
34
+ "lib/safely/strategy/log.rb",
35
+ "lib/safely/strategy/mail.rb",
31
36
  "safely.gemspec",
32
37
  "spec/config_spec.rb",
33
38
  "spec/safely_spec.rb",
34
- "spec/spec_helper.rb"
39
+ "spec/spec_helper.rb",
40
+ "spec/strategies/hoptoad_spec.rb",
41
+ "spec/strategies/log_spec.rb",
42
+ "spec/strategies/mail_spec.rb",
43
+ "spec/support/fake_logger.rb"
35
44
  ]
36
45
  s.homepage = %q{http://github.com/kennethkalmer/safely}
37
46
  s.licenses = ["MIT"]
@@ -41,7 +50,11 @@ Gem::Specification.new do |s|
41
50
  s.test_files = [
42
51
  "spec/config_spec.rb",
43
52
  "spec/safely_spec.rb",
44
- "spec/spec_helper.rb"
53
+ "spec/spec_helper.rb",
54
+ "spec/strategies/hoptoad_spec.rb",
55
+ "spec/strategies/log_spec.rb",
56
+ "spec/strategies/mail_spec.rb",
57
+ "spec/support/fake_logger.rb"
45
58
  ]
46
59
 
47
60
  if s.respond_to? :specification_version then
@@ -49,6 +62,7 @@ Gem::Specification.new do |s|
49
62
 
50
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
64
  s.add_development_dependency(%q<toadhopper>, [">= 0"])
65
+ s.add_development_dependency(%q<mail>, [">= 0"])
52
66
  s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
53
67
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
54
68
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -57,6 +71,7 @@ Gem::Specification.new do |s|
57
71
  s.add_development_dependency(%q<mocha>, [">= 0"])
58
72
  else
59
73
  s.add_dependency(%q<toadhopper>, [">= 0"])
74
+ s.add_dependency(%q<mail>, [">= 0"])
60
75
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
61
76
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
62
77
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -66,6 +81,7 @@ Gem::Specification.new do |s|
66
81
  end
67
82
  else
68
83
  s.add_dependency(%q<toadhopper>, [">= 0"])
84
+ s.add_dependency(%q<mail>, [">= 0"])
69
85
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
70
86
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
71
87
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Safely::Strategy::Log do
4
+ it "should support setting a logger" do
5
+ Safely::Strategy::Log.should respond_to(:logger)
6
+ Safely::Strategy::Log.should respond_to(:logger=)
7
+ end
8
+
9
+ it "should support setting flushing" do
10
+ Safely::Strategy::Log.should respond_to(:flush)
11
+ Safely::Strategy::Log.should respond_to(:flush=)
12
+ end
13
+
14
+ describe "reporting" do
15
+ it "should log exceptions when configured" do
16
+ logger = FakeLogger.new
17
+
18
+ Safely::Strategy::Log.logger = logger
19
+
20
+ safely do
21
+ raise "Argh"
22
+ end
23
+
24
+ logger.lines.should_not be_empty
25
+ logger.to_s.should match(/RuntimeError/)
26
+ logger.to_s.should match(/Backtrace/)
27
+ end
28
+
29
+ it "should flush logger when configured" do
30
+ logger = FakeLogger.new
31
+
32
+ Safely::Strategy::Log.logger = logger
33
+ Safely::Strategy::Log.flush = true
34
+
35
+ logger.expects(:flush)
36
+
37
+ safely do
38
+ raise "Argh"
39
+ end
40
+ end
41
+
42
+ it "should do nothing if not configured" do
43
+ safely do
44
+ raise "Argh"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ class FakeLogger
2
+
3
+ attr_reader :lines
4
+
5
+ def initialize
6
+ @lines = []
7
+ end
8
+
9
+ def error( message )
10
+ @lines << message
11
+ end
12
+
13
+ def to_s
14
+ @lines.join("\n")
15
+ end
16
+
17
+ def flush
18
+ @flush = true
19
+ end
20
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: safely
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kenneth Kalmer
@@ -124,13 +124,16 @@ files:
124
124
  - lib/safely/mixin.rb
125
125
  - lib/safely/strategy.rb
126
126
  - lib/safely/strategy/hoptoad.rb
127
+ - lib/safely/strategy/log.rb
127
128
  - lib/safely/strategy/mail.rb
128
129
  - safely.gemspec
129
130
  - spec/config_spec.rb
130
131
  - spec/safely_spec.rb
131
132
  - spec/spec_helper.rb
132
133
  - spec/strategies/hoptoad_spec.rb
134
+ - spec/strategies/log_spec.rb
133
135
  - spec/strategies/mail_spec.rb
136
+ - spec/support/fake_logger.rb
134
137
  homepage: http://github.com/kennethkalmer/safely
135
138
  licenses:
136
139
  - MIT
@@ -144,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
147
  requirements:
145
148
  - - ">="
146
149
  - !ruby/object:Gem::Version
147
- hash: -2395968726711885681
150
+ hash: -2463736658289113276
148
151
  segments:
149
152
  - 0
150
153
  version: "0"
@@ -166,4 +169,6 @@ test_files:
166
169
  - spec/safely_spec.rb
167
170
  - spec/spec_helper.rb
168
171
  - spec/strategies/hoptoad_spec.rb
172
+ - spec/strategies/log_spec.rb
169
173
  - spec/strategies/mail_spec.rb
174
+ - spec/support/fake_logger.rb