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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17faa5426332cbf2e4feef95b01dce87da18cbd5
4
- data.tar.gz: c3443b989de0b26626635c564a4f226fd2d3cf03
3
+ metadata.gz: d52060122b7a4d83a2a2b2bea5e393e638f4cccf
4
+ data.tar.gz: 5d31718797355f9c4cf5577af3a6e03aeaf2a86e
5
5
  SHA512:
6
- metadata.gz: af2e443c83eff05d51c31acd6609145ac37b1c07bc13357fcc817262cbc7c5893bd55395a8a4db04e83df81711feaf450fddd92b85cfdd3f4c5bb53ce9a78f79
7
- data.tar.gz: 9dea5ef86e1cc1f577aebe6010792580c29d258388ea714992f4cdd1302a7d5fdf7c7c76a48187b3dcc650b9dacfc5d29a70c629fc3f4914db7820c95aa88b4c
6
+ metadata.gz: c5a0c332cce2f4e75ee24a35db64fdd0215161097c2cefb7e2de3cea0c724379d75163bc83e6877c2d8998580f43e296aebcf80af0746157088fadbb54f0d705
7
+ data.tar.gz: 02bedea663577ccb182fcc42148ec57954665387747d8a8c89a1d850fc895e9962ad5d14244353a387fcc60679282be9dbe32ef77ed21cc618e11638e9550a95
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rya (0.4.0)
4
+ rya (0.5.0)
5
5
  abort_if (~> 0.2.0)
6
6
  systemu (~> 2.6, >= 2.6.5)
7
7
 
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rya
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.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: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2019-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler