nifty-utils 1.0.8 → 1.0.9
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5830c82f749532ed226146ff4c5212b409d7dbf3
|
4
|
+
data.tar.gz: f940f1e50c8a70acd8de64a3effd56554b5672e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 771f362ad4217d746d21df368e8fbb1cd0a90242f0218893996e0b4da324f2a8db4cea526fde12f0ad32f3a0d510af630ed724b97224aa9a8308bfb5aa55f1ac
|
7
|
+
data.tar.gz: 4de7a80c3bb90b5a5860dafefc93f508872298fae2a632d54d06f95e390f106437a02c56a7f880a36add83fff6f328b4954feb24ee5e3bec9be6eb7aea72fdfd
|
@@ -1 +1,2 @@
|
|
1
|
-
require 'nifty/utils/extensions/
|
1
|
+
require 'nifty/utils/extensions/object'
|
2
|
+
require 'nifty/utils/extensions/string'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Nifty
|
2
|
+
module Utils
|
3
|
+
module UntilWithMaxAttempts
|
4
|
+
|
5
|
+
#
|
6
|
+
# The exception which will be raised if the maximum number of attempts
|
7
|
+
# is reached.
|
8
|
+
#
|
9
|
+
class MaxAttemptsReached < StandardError; end
|
10
|
+
|
11
|
+
#
|
12
|
+
# Like a usual while block but with a maximum attempt counter. Can be used
|
13
|
+
# like this
|
14
|
+
#
|
15
|
+
# Attempts.until proc { job.completed? }, :attempts => 10, :gap => 5 do
|
16
|
+
# puts "Waiting for job to complete..."
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# The proc is the condition which will be evaluated, :attempts sets the
|
20
|
+
# maximum number of times it will wait before raising an exception and :gap
|
21
|
+
# is the length of time in seconds to wait between each check.
|
22
|
+
#
|
23
|
+
def self.until(condition, options = {}, &block)
|
24
|
+
options[:attempts] ||= 10
|
25
|
+
count = 0
|
26
|
+
until condition.call
|
27
|
+
|
28
|
+
if count == options[:attempts]
|
29
|
+
raise MaxAttemptsReached, "Maximum attempts reached (#{options[:attempts]}) without success"
|
30
|
+
end
|
31
|
+
|
32
|
+
yield
|
33
|
+
|
34
|
+
count += 1
|
35
|
+
|
36
|
+
if options[:gap] && count < options[:attempts]
|
37
|
+
sleep options[:gap]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/nifty/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nifty-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A set of useful utilties for Rails applications
|
13
|
+
description: A set of useful utilties for Rails applications.
|
14
14
|
email:
|
15
|
-
- adam@
|
15
|
+
- adam@atechmedia.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
@@ -22,13 +22,16 @@ files:
|
|
22
22
|
- lib/nifty/utils/active_record/inquirer.rb
|
23
23
|
- lib/nifty/utils/active_record/random_string.rb
|
24
24
|
- lib/nifty/utils/extensions/core.rb
|
25
|
+
- lib/nifty/utils/extensions/object.rb
|
25
26
|
- lib/nifty/utils/extensions/string.rb
|
26
27
|
- lib/nifty/utils/railtie.rb
|
27
28
|
- lib/nifty/utils/random_string.rb
|
29
|
+
- lib/nifty/utils/until_with_max_attempts.rb
|
28
30
|
- lib/nifty/utils/version.rb
|
29
31
|
- lib/nifty/utils/view_helpers.rb
|
30
|
-
homepage: https://github.com/
|
31
|
-
licenses:
|
32
|
+
homepage: https://github.com/atech/nifty-utils
|
33
|
+
licenses:
|
34
|
+
- MIT
|
32
35
|
metadata: {}
|
33
36
|
post_install_message:
|
34
37
|
rdoc_options: []
|
@@ -49,5 +52,5 @@ rubyforge_project:
|
|
49
52
|
rubygems_version: 2.2.2
|
50
53
|
signing_key:
|
51
54
|
specification_version: 4
|
52
|
-
summary: A
|
55
|
+
summary: A collection of functions which expand upon ActiveRecord and ActionView.
|
53
56
|
test_files: []
|