progressrus 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.
- checksums.yaml +4 -4
- data/lib/progressrus.rb +7 -3
- data/lib/progressrus/version.rb +1 -1
- data/test/progressrus_test.rb +14 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9443b1b626649e1d9e17aa2ed9ef9354312bc78
|
4
|
+
data.tar.gz: 4e9bd7b04d2f47975bfc9bbfa96f36ced10e3ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8093bed5b344ff65be4f5bc8b0ec207eb1984c4fb7f45ea629e0c6d7306f2a6fbfc0cf645bd7d73940b3ec8368ffb87235edac040c2805fe28c0113d70b9908
|
7
|
+
data.tar.gz: 71e0a98fc087451ad400f72c16d3c461873a93c75ba27ec90231dae1610ecc5b724e346603a51b06f6de64889360dc9769e441d3dec69c7130ff7500a8d38b49
|
data/lib/progressrus.rb
CHANGED
@@ -42,7 +42,7 @@ class Progressrus
|
|
42
42
|
completed_at: nil, started_at: nil, count: 0, failed_at: nil,
|
43
43
|
error_count: 0, persist: false, expires_at: nil)
|
44
44
|
|
45
|
-
raise ArgumentError, "Total cannot be
|
45
|
+
raise ArgumentError, "Total cannot be negative." if total && total < 0
|
46
46
|
|
47
47
|
@name = name || id
|
48
48
|
@scope = Array(scope).map(&:to_s)
|
@@ -120,7 +120,7 @@ class Progressrus
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def total=(new_total)
|
123
|
-
raise ArgumentError, "Total cannot be
|
123
|
+
raise ArgumentError, "Total cannot be negative." if new_total < 0
|
124
124
|
@total = new_total
|
125
125
|
end
|
126
126
|
|
@@ -133,7 +133,11 @@ class Progressrus
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def percentage
|
136
|
-
|
136
|
+
if total > 0
|
137
|
+
count.to_f / total
|
138
|
+
else
|
139
|
+
1.0
|
140
|
+
end
|
137
141
|
end
|
138
142
|
|
139
143
|
def eta(now: Time.now)
|
data/lib/progressrus/version.rb
CHANGED
data/test/progressrus_test.rb
CHANGED
@@ -110,10 +110,17 @@ class ProgressrusTest < Minitest::Test
|
|
110
110
|
assert_equal 1.2, @progress.percentage
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def test_percentage_should_be_0_if_count_0
|
114
114
|
assert_equal 0, @progress.percentage
|
115
115
|
end
|
116
116
|
|
117
|
+
def test_percentage_should_be_1_if_total_0
|
118
|
+
progress = Progressrus.new(total: 0)
|
119
|
+
assert_equal 1, progress.percentage
|
120
|
+
progress.tick
|
121
|
+
assert_equal 1, progress.percentage
|
122
|
+
end
|
123
|
+
|
117
124
|
def test_elapsed_should_return_the_delta_between_now_and_started_at
|
118
125
|
time = Time.now
|
119
126
|
@progress.tick(10, now: time - 10)
|
@@ -168,10 +175,9 @@ class ProgressrusTest < Minitest::Test
|
|
168
175
|
assert_equal now.to_i, @progress.completed_at.to_i
|
169
176
|
end
|
170
177
|
|
171
|
-
def
|
172
|
-
|
173
|
-
|
174
|
-
end
|
178
|
+
def test_should_be_able_to_set_total_to_0
|
179
|
+
@progress.total = 0
|
180
|
+
assert_equal 0, @progress.total
|
175
181
|
end
|
176
182
|
|
177
183
|
def test_should_not_be_able_to_set_total_to_a_negative_number
|
@@ -199,10 +205,9 @@ class ProgressrusTest < Minitest::Test
|
|
199
205
|
@progress.complete
|
200
206
|
end
|
201
207
|
|
202
|
-
def
|
203
|
-
|
204
|
-
|
205
|
-
end
|
208
|
+
def test_should_be_able_to_initialize_with_total_0
|
209
|
+
progress = Progressrus.new(total: 0)
|
210
|
+
assert_equal 0, progress.total
|
206
211
|
end
|
207
212
|
|
208
213
|
def test_should_not_be_able_to_initialize_with_total_as_a_negative_number
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progressrus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Eskildsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.2.3
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Monitor the progress of remote, long-running jobs.
|