theusual 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/theusual.rb +25 -2
- data/lib/theusual/failure.rb +30 -0
- data/lib/theusual/hash.rb +9 -0
- data/lib/theusual/version.rb +3 -0
- data/test/test_failure.rb +25 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51de97d541d5c8a0934ea2b4a4390c2f206667e8
|
4
|
+
data.tar.gz: 222dd58985ce29ef1fc4b72185f572dd0cfe9393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac7e54c933c172e01c740d643b70335123f35cf71fd05ac23ac9e77102df7c7990324757a16ae0fc63139e66e4ebe3fd9a03d49a8e87b0522aeb4aa484b3f18
|
7
|
+
data.tar.gz: b7919d2c8876305931982515340f2a4eaaf5fbff0df9849a92e4ea2fde4a1d8ec08b81102e470826501ccfc083ed31e5d35f6e83a59c07a0c9c44266080d421d
|
data/lib/theusual.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'set'
|
2
|
+
require_relative 'theusual/version.rb'
|
3
|
+
|
3
4
|
|
5
|
+
module TheUsual
|
4
6
|
MODULES = [
|
5
7
|
'array',
|
8
|
+
'failure',
|
6
9
|
'hash',
|
7
10
|
'ipaddr',
|
8
11
|
'mongoid',
|
@@ -11,6 +14,11 @@ module TheUsual
|
|
11
14
|
'time',
|
12
15
|
]
|
13
16
|
|
17
|
+
# functions defined in sub-libs that can be include-ed
|
18
|
+
# into another namespace
|
19
|
+
@include_fns = Set.new
|
20
|
+
|
21
|
+
|
14
22
|
def self.load *modules
|
15
23
|
# some modules need to be explicitly required
|
16
24
|
needs_load = [
|
@@ -60,4 +68,19 @@ module TheUsual
|
|
60
68
|
end
|
61
69
|
end.compact
|
62
70
|
end
|
71
|
+
|
72
|
+
|
73
|
+
def self.include_fn fn
|
74
|
+
@include_fns << fn
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def self.included base
|
79
|
+
@include_fns.each do |name|
|
80
|
+
base.send :define_method, name do |*args|
|
81
|
+
TheUsual.method(name).send *args
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
63
86
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module TheUsual
|
2
|
+
|
3
|
+
def self.retry opts = {}
|
4
|
+
tries = opts[:tries] || 2
|
5
|
+
|
6
|
+
exceptions = Array(opts[:e])
|
7
|
+
exceptions += Array(opts[:exceptions])
|
8
|
+
if exceptions.empty?
|
9
|
+
exceptions = [ Exception ]
|
10
|
+
end
|
11
|
+
|
12
|
+
# callback = opts[:callback]
|
13
|
+
|
14
|
+
res = nil
|
15
|
+
tries.times do
|
16
|
+
begin
|
17
|
+
res = yield
|
18
|
+
break
|
19
|
+
rescue Exception => e
|
20
|
+
raise unless exceptions.any? {|x| e < x }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
res
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
TheUsual::include_fn :retry
|
data/lib/theusual/hash.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'theusual'
|
3
|
+
TheUsual::load 'failure'
|
4
|
+
|
5
|
+
|
6
|
+
class FailureTest < Minitest::Test
|
7
|
+
|
8
|
+
def test_sum
|
9
|
+
data = [ true ]
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
[ false, true ]
|
14
|
+
[ false, false, true ]
|
15
|
+
# assert_nothing_raised RuntimeError do
|
16
|
+
# raise Exception #Assertion passes, Exception is not a RuntimeError
|
17
|
+
# end
|
18
|
+
|
19
|
+
# assert_raise NameError do
|
20
|
+
# puts x #Raises NameError, so assertion succeeds
|
21
|
+
# end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theusual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
27
41
|
description: A handful of useful hacks...good for any project
|
28
42
|
email:
|
29
43
|
executables: []
|
@@ -32,13 +46,16 @@ extra_rdoc_files: []
|
|
32
46
|
files:
|
33
47
|
- lib/theusual.rb
|
34
48
|
- lib/theusual/array.rb
|
49
|
+
- lib/theusual/failure.rb
|
35
50
|
- lib/theusual/hash.rb
|
36
51
|
- lib/theusual/ipaddr.rb
|
37
52
|
- lib/theusual/mongoid.rb
|
38
53
|
- lib/theusual/ssh.rb
|
39
54
|
- lib/theusual/string.rb
|
40
55
|
- lib/theusual/time.rb
|
56
|
+
- lib/theusual/version.rb
|
41
57
|
- test/test_array.rb
|
58
|
+
- test/test_failure.rb
|
42
59
|
- test/test_hash.rb
|
43
60
|
- test/test_ip_addr.rb
|
44
61
|
- test/test_string.rb
|
@@ -69,6 +86,7 @@ specification_version: 4
|
|
69
86
|
summary: TheUsual
|
70
87
|
test_files:
|
71
88
|
- test/test_array.rb
|
89
|
+
- test/test_failure.rb
|
72
90
|
- test/test_hash.rb
|
73
91
|
- test/test_ip_addr.rb
|
74
92
|
- test/test_string.rb
|