tryout 0.1.0 → 0.1.1
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.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- data/Rakefile +19 -0
- data/lib/tryout.rb +4 -4
- data/lib/tryout/version.rb +1 -1
- data/spec/tryout_spec.rb +9 -0
- metadata +3 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tryout (0.1.
|
4
|
+
tryout (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -12,6 +12,7 @@ GEM
|
|
12
12
|
diff-lcs (1.1.3)
|
13
13
|
i18n (0.6.1)
|
14
14
|
multi_json (1.5.0)
|
15
|
+
rake (10.0.3)
|
15
16
|
redcarpet (2.2.2)
|
16
17
|
rspec (2.12.0)
|
17
18
|
rspec-core (~> 2.12.0)
|
@@ -32,6 +33,7 @@ PLATFORMS
|
|
32
33
|
|
33
34
|
DEPENDENCIES
|
34
35
|
activesupport (>= 3.0.0)
|
36
|
+
rake
|
35
37
|
redcarpet (~> 2.2.2)
|
36
38
|
rspec (>= 2.0.0)
|
37
39
|
simplecov
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ internet connectivity lost.
|
|
14
14
|
How to use
|
15
15
|
---
|
16
16
|
|
17
|
-
|
17
|
+
value = Tryout.try { RestClient.get('http://www.google.com') }.retry(3)
|
18
18
|
|
19
19
|
**if/unless**: call any method on the result of the `try` block.
|
20
20
|
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$: << 'lib'
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'tryout'
|
6
|
+
|
7
|
+
require "rspec/core/rake_task"
|
8
|
+
|
9
|
+
desc "Run all specs"
|
10
|
+
task :spec => ["spec:all"]
|
11
|
+
|
12
|
+
desc "Run unit specs"
|
13
|
+
RSpec::Core::RakeTask.new(:'spec:all') do |t|
|
14
|
+
t.rspec_opts = ['--colour']
|
15
|
+
t.pattern = 'spec/**/*_spec.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :spec
|
19
|
+
|
data/lib/tryout.rb
CHANGED
@@ -30,7 +30,7 @@ class Tryout
|
|
30
30
|
# @option [Symbol] unless method to call from result
|
31
31
|
#
|
32
32
|
# @return [Object] result from block call
|
33
|
-
def retry(times = 2, conditions =
|
33
|
+
def retry(times = 2, conditions = {}, &evaluator)
|
34
34
|
result = @block.call
|
35
35
|
|
36
36
|
# Call block to evaluate valid result
|
@@ -59,12 +59,12 @@ class Tryout
|
|
59
59
|
# @param [Object] result
|
60
60
|
# @param [Hash] conditions
|
61
61
|
# @return [Boolean] need a retry?
|
62
|
-
def apply_conditions?(result, conditions)
|
62
|
+
def apply_conditions?(result, conditions={})
|
63
63
|
negation = conditions.has_key?(:unless)
|
64
64
|
bool = if conditions.has_key?(:match)
|
65
65
|
conditions[:match]
|
66
|
-
|
67
|
-
result.send(
|
66
|
+
elsif (method = conditions[:if] || conditions[:unless])
|
67
|
+
result.send(method)
|
68
68
|
end
|
69
69
|
|
70
70
|
(negation) ? !bool : bool
|
data/lib/tryout/version.rb
CHANGED
data/spec/tryout_spec.rb
CHANGED
@@ -5,6 +5,15 @@ describe Tryout do
|
|
5
5
|
Tryout::VERSION.should be_a(String)
|
6
6
|
end
|
7
7
|
|
8
|
+
it "should retry 2 times" do
|
9
|
+
sample = [
|
10
|
+
lambda { raise "error!" },
|
11
|
+
lambda { raise "error!" },
|
12
|
+
lambda { "fine!" }
|
13
|
+
].each
|
14
|
+
Tryout.try { sample.next.call }.retry(3).should == "fine!"
|
15
|
+
end
|
16
|
+
|
8
17
|
it "should retry 3 times" do
|
9
18
|
sample = [1,2,3].each
|
10
19
|
valid = Tryout.try do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tryout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- Gemfile.lock
|
90
90
|
- LICENSE
|
91
91
|
- README.md
|
92
|
+
- Rakefile
|
92
93
|
- lib/tryout.rb
|
93
94
|
- lib/tryout/version.rb
|
94
95
|
- spec/spec_helper.rb
|