rya 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rya.rb +7 -0
- data/lib/rya/core_extensions.rb +54 -0
- data/lib/rya/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d52060122b7a4d83a2a2b2bea5e393e638f4cccf
|
4
|
+
data.tar.gz: 5d31718797355f9c4cf5577af3a6e03aeaf2a86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5a0c332cce2f4e75ee24a35db64fdd0215161097c2cefb7e2de3cea0c724379d75163bc83e6877c2d8998580f43e296aebcf80af0746157088fadbb54f0d705
|
7
|
+
data.tar.gz: 02bedea663577ccb182fcc42148ec57954665387747d8a8c89a1d850fc895e9962ad5d14244353a387fcc60679282be9dbe32ef77ed21cc618e11638e9550a95
|
data/Gemfile.lock
CHANGED
data/lib/rya.rb
CHANGED
@@ -7,6 +7,13 @@ require "rya/version"
|
|
7
7
|
require "rya/core_extensions"
|
8
8
|
|
9
9
|
module Rya
|
10
|
+
# Provide errors for the Rya class.
|
11
|
+
class Error < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
class MaxAttemptsExceededError < Error
|
15
|
+
end
|
16
|
+
|
10
17
|
# If you want to use AbortIf from this module, you can use it as Rya::AbortIf
|
11
18
|
module AbortIf
|
12
19
|
# To include the methods
|
data/lib/rya/core_extensions.rb
CHANGED
@@ -109,6 +109,60 @@ module Rya
|
|
109
109
|
module Process
|
110
110
|
include CoreExtensions::Time
|
111
111
|
|
112
|
+
# I run your program until it succeeds or I fail too many times.
|
113
|
+
#
|
114
|
+
# @example I'll keep retrying your command line program until it succeeds.
|
115
|
+
# klass = Class.new { extend Rya::CoreExtensions::Process }
|
116
|
+
# max_attempts = 10
|
117
|
+
#
|
118
|
+
# tries = klass.run_until_success max_attempts do
|
119
|
+
# # This command returns a Process::Status object!
|
120
|
+
# klass.run_it "echo 'hi'"
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# tries == 1 #=> true
|
124
|
+
#
|
125
|
+
# @example I'll raise an error if the program doesn't succeed after max_attempts tries.
|
126
|
+
# klass = Class.new { extend Rya::CoreExtensions::Process }
|
127
|
+
# max_attempts = 10
|
128
|
+
#
|
129
|
+
# begin
|
130
|
+
# klass.run_until_success max_attempts do
|
131
|
+
# # This command returns a Process::Status object!
|
132
|
+
# klass.run_it "ls 'file_that_doesnt_exist'"
|
133
|
+
# end
|
134
|
+
# rescue Rya::MaxAttemptsExceededError => err
|
135
|
+
# STDERR.puts "The command didn't succeed after #{max_attempts} tries!"
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# @param max_attempts [Integer] max attempts before I fail
|
139
|
+
#
|
140
|
+
# @yield The block specifies the command you want to run. Make sure that it returns something that responds to exitstatus!
|
141
|
+
#
|
142
|
+
# @return [Integer] the number of attempts before successful completion
|
143
|
+
#
|
144
|
+
# @raise [Rya::Error] if the block does not return an object that responds to exitstatus (e.g., Prosses::Status)
|
145
|
+
# @raise [Rya::MaxAttemptsExceededError] if the program fails more than max_attempts times
|
146
|
+
#
|
147
|
+
def run_until_success max_attempts, &block
|
148
|
+
max_attempts.times do |attempt_index|
|
149
|
+
proc_status = yield block
|
150
|
+
|
151
|
+
unless proc_status.respond_to? :exitstatus
|
152
|
+
raise Rya::Error, "The block did not return an object that responds to exitstatus"
|
153
|
+
end
|
154
|
+
|
155
|
+
puts "proc_status in run_until_success fn: #{proc_status.inspect}"
|
156
|
+
|
157
|
+
if proc_status.exitstatus.zero?
|
158
|
+
return attempt_index + 1
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
raise Rya::MaxAttemptsExceededError, "max_attempts exceeded"
|
163
|
+
end
|
164
|
+
|
165
|
+
|
112
166
|
# Runs a command and outputs stdout and stderr
|
113
167
|
def run_it *a, &b
|
114
168
|
exit_status, stdout, stderr = systemu *a, &b
|
data/lib/rya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|