robustly 0.0.3 → 0.0.4
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 +4 -4
- data/.rubocop.yml +32 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/lib/robustly.rb +7 -7
- data/lib/robustly/version.rb +1 -1
- data/robustly.gemspec +4 -4
- data/test/robustly_test.rb +11 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3358a29e863fa2ee454fe1d98b28cce45552d8be
|
4
|
+
data.tar.gz: 36d2b9074c3539947d8b84471a5e02207db631a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1533250d894eb14a9cf777554b0c6f02db0df96d472eda9c4898fd7e95f848312c53de1367b4ec906ee62d2024139bde2e6ce1f9962454b2b5bfc87b1a0136a3
|
7
|
+
data.tar.gz: 350ad47a7bf3e6b4f643e7cc8e910dde3fed37c0852acfe9b1967dcfba39fe690b075fa35aabf7c898b5a041773e39adf9cd66704a9301b64f3a3793d205cd6b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
EnforcedStyle: double_quotes
|
3
|
+
|
4
|
+
Style/SpaceInsideHashLiteralBraces:
|
5
|
+
EnforcedStyle: no_space
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/SignalException:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/BlockNesting:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/ClassLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/LineLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Metrics/PerceivedComplexity:
|
32
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/robustly.rb
CHANGED
@@ -2,7 +2,6 @@ require "robustly/version"
|
|
2
2
|
require "errbase"
|
3
3
|
|
4
4
|
module Robustly
|
5
|
-
|
6
5
|
class << self
|
7
6
|
attr_accessor :env, :report_exception_method
|
8
7
|
|
@@ -16,24 +15,25 @@ module Robustly
|
|
16
15
|
end
|
17
16
|
|
18
17
|
module Methods
|
19
|
-
|
20
|
-
def safely(options = {}, &block)
|
18
|
+
def safely(options = {})
|
21
19
|
class_names = Array(options[:only] || StandardError)
|
22
20
|
begin
|
23
21
|
yield
|
24
22
|
rescue *class_names => e
|
25
|
-
raise e if %w
|
23
|
+
raise e if %w(development test).include?(Robustly.env)
|
26
24
|
if options[:throttle] ? rand < 1.0 / options[:throttle] : true
|
27
|
-
|
25
|
+
begin
|
26
|
+
Robustly.report_exception(e)
|
27
|
+
rescue => e2
|
28
|
+
$stderr.puts "FAIL-SAFE #{e2.class.name}: #{e2.message}"
|
29
|
+
end
|
28
30
|
end
|
29
31
|
options[:default]
|
30
32
|
end
|
31
33
|
end
|
32
34
|
alias_method :yolo, :safely
|
33
35
|
alias_method :robustly, :safely # legacy
|
34
|
-
|
35
36
|
end
|
36
|
-
|
37
37
|
end
|
38
38
|
|
39
39
|
Object.send :include, Robustly::Methods
|
data/lib/robustly/version.rb
CHANGED
data/robustly.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "robustly/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "robustly"
|
8
8
|
spec.version = Robustly::VERSION
|
9
9
|
spec.authors = ["Andrew Kane"]
|
10
10
|
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Don’t let small errors bring down the system"
|
12
|
+
spec.description = "Don’t let small errors bring down the system"
|
13
13
|
spec.homepage = "https://github.com/ankane/robustly"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/test/robustly_test.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class TestRobustly < Minitest::Test
|
4
|
-
|
5
4
|
def setup
|
6
5
|
Robustly.env = "production"
|
7
|
-
Robustly.report_exception_method = proc {|e| Errbase.report(e) }
|
6
|
+
Robustly.report_exception_method = proc { |e| Errbase.report(e) }
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_safely_development_environment
|
@@ -29,7 +28,7 @@ class TestRobustly < Minitest::Test
|
|
29
28
|
exception = Robustly::TestError.new
|
30
29
|
mock = MiniTest::Mock.new
|
31
30
|
mock.expect :report_exception, nil, [exception]
|
32
|
-
Robustly.report_exception_method = proc {|e| mock.report_exception(e) }
|
31
|
+
Robustly.report_exception_method = proc { |e| mock.report_exception(e) }
|
33
32
|
safely do
|
34
33
|
raise exception
|
35
34
|
end
|
@@ -40,7 +39,7 @@ class TestRobustly < Minitest::Test
|
|
40
39
|
exception = Robustly::TestError.new
|
41
40
|
mock = MiniTest::Mock.new
|
42
41
|
mock.expect :report_exception, nil, [exception]
|
43
|
-
Robustly.report_exception_method = proc {|e| mock.report_exception(e) }
|
42
|
+
Robustly.report_exception_method = proc { |e| mock.report_exception(e) }
|
44
43
|
yolo do
|
45
44
|
raise exception
|
46
45
|
end
|
@@ -51,7 +50,7 @@ class TestRobustly < Minitest::Test
|
|
51
50
|
exception = Robustly::TestError.new
|
52
51
|
mock = MiniTest::Mock.new
|
53
52
|
mock.expect :report_exception, nil, [exception]
|
54
|
-
Robustly.report_exception_method = proc {|e| mock.report_exception(e) }
|
53
|
+
Robustly.report_exception_method = proc { |e| mock.report_exception(e) }
|
55
54
|
robustly do
|
56
55
|
raise exception
|
57
56
|
end
|
@@ -78,4 +77,11 @@ class TestRobustly < Minitest::Test
|
|
78
77
|
assert_raises(RuntimeError, "Boom") { safely(only: [Robustly::TestError]) { raise RuntimeError.new("Boom") } }
|
79
78
|
end
|
80
79
|
|
80
|
+
def test_failsafe
|
81
|
+
Robustly.report_exception_method = proc { raise "oops" }
|
82
|
+
out, err = capture_io do
|
83
|
+
safely { raise "boom" }
|
84
|
+
end
|
85
|
+
assert_equal "FAIL-SAFE RuntimeError: oops\n", err
|
86
|
+
end
|
81
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robustly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: errbase
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.5
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Don’t let small errors bring down the system
|