progressrus 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/progressrus.rb +23 -2
- data/lib/progressrus/version.rb +1 -1
- data/test/progressrus_test.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5cd2369da367f85505ff94038ed56c4d5e492732e9993b595a0c96acdaf265b
|
4
|
+
data.tar.gz: 23e4444e32c105d2565f093c607ddc7ece5b74624af9628cf3297740af889dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb1621312d260fd16afa68931fc34a4c6b17ca9a7db6a4ef3a5ccfd8534c8fe8c91821728214609288d54294370444be98006f325f3cd00b32ab3b2a0f59b315
|
7
|
+
data.tar.gz: e431e6c4857aa31025dd39e0dff73683a32aca87bea5664bc21cc2988f430d286290f7f187b3816c8959818ac52ead468426d085728444781c56587ddd59fadd
|
data/lib/progressrus.rb
CHANGED
@@ -21,6 +21,16 @@ class Progressrus
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
class StoreNotFoundError < StandardError
|
25
|
+
def initialize(store)
|
26
|
+
message = <<~MSG
|
27
|
+
The store `#{store}` does not exists.
|
28
|
+
Available stores: #{Progressrus.stores.keys.join(', ')}
|
29
|
+
MSG
|
30
|
+
super(message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
class << self
|
25
35
|
attr_reader :mutex
|
26
36
|
|
@@ -74,7 +84,7 @@ class Progressrus
|
|
74
84
|
attr_writer :params
|
75
85
|
|
76
86
|
def initialize(scope: "progressrus", total: nil, name: nil,
|
77
|
-
id: SecureRandom.uuid, params: {}, stores:
|
87
|
+
id: SecureRandom.uuid, params: {}, stores: nil,
|
78
88
|
completed_at: nil, started_at: nil, count: 0, failed_at: nil,
|
79
89
|
error_count: 0, persist: false, expires_at: nil, persisted: false)
|
80
90
|
|
@@ -85,7 +95,7 @@ class Progressrus
|
|
85
95
|
@total = total
|
86
96
|
@id = id
|
87
97
|
@params = params
|
88
|
-
@stores = stores
|
98
|
+
@stores = extract_stores(stores)
|
89
99
|
@count = count
|
90
100
|
@error_count = error_count
|
91
101
|
|
@@ -196,6 +206,17 @@ class Progressrus
|
|
196
206
|
|
197
207
|
private
|
198
208
|
|
209
|
+
def extract_stores(stores)
|
210
|
+
return Progressrus.stores unless stores
|
211
|
+
|
212
|
+
Array(stores).each_with_object({}) do |store, hash|
|
213
|
+
stored_found = Progressrus.stores[store]
|
214
|
+
raise StoreNotFoundError, store unless stored_found
|
215
|
+
|
216
|
+
hash[store] = stored_found
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
199
220
|
def persist(force: false)
|
200
221
|
stores.each_value do |store|
|
201
222
|
begin
|
data/lib/progressrus/version.rb
CHANGED
data/test/progressrus_test.rb
CHANGED
@@ -40,6 +40,37 @@ class ProgressrusTest < Minitest::Test
|
|
40
40
|
assert_equal 'Wally', progressrus.name
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_not_passing_stores_default_to_all_stores
|
44
|
+
progressrus = Progressrus.new(scope: ['walruses', 1])
|
45
|
+
assert_equal Progressrus.stores, progressrus.stores
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_passing_stores
|
49
|
+
mysql = mock_store
|
50
|
+
Progressrus.add_store(:mysql, mysql)
|
51
|
+
progressrus = Progressrus.new(scope: ['walruses', 1], stores: :mysql)
|
52
|
+
assert_equal({ mysql: mysql }, progressrus.stores)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_passing_multiple_stores
|
56
|
+
Progressrus.clear_stores
|
57
|
+
|
58
|
+
mysql = mock_store
|
59
|
+
redis = mock_store
|
60
|
+
|
61
|
+
Progressrus.add_store(:mysql, mysql)
|
62
|
+
Progressrus.add_store(:redis, redis)
|
63
|
+
|
64
|
+
progressrus = Progressrus.new(scope: ['walruses', 1], stores: %i(mysql redis))
|
65
|
+
assert_equal({ mysql: mysql, redis: redis }, progressrus.stores)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_passing_non_existing_store_raises_error
|
69
|
+
assert_raises(Progressrus::StoreNotFoundError) do
|
70
|
+
Progressrus.new(scope: ['walruses', 1], stores: :not_found)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
43
74
|
def test_initialize_without_name_should_use_id
|
44
75
|
progressrus = Progressrus.new(id: 'oemg')
|
45
76
|
assert_equal 'oemg', progressrus.name
|
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: 1.0.
|
4
|
+
version: 1.0.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: 2019-09-
|
11
|
+
date: 2019-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|