batch-loader 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/batch_loader.rb +18 -11
- data/lib/batch_loader/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: 0cb2bec5ff8fdc6fd2c2ec099c1db9ca07916594
|
4
|
+
data.tar.gz: af763f4dc852c3f2b4ca73a3ce0ff639ea544f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 699d6d95a80c2b7b7c366979277bb003c0eada94ea087df1812b2b1754ac70d6a518608bd25c7ae3d6665d6d0629c9836811c2e9d0e07bf3879064bf4f0b11c7
|
7
|
+
data.tar.gz: 614b0b57b84e80a7f1de5af9d961c4ca78252e4c84e3a624fa49a25810acae7c6ec2648c8a573cddc2b9620896645d966d79b8c936c02f09b3cca0eb1a445d18
|
data/CHANGELOG.md
CHANGED
@@ -8,10 +8,14 @@ one of the following labels: `Added`, `Changed`, `Deprecated`,
|
|
8
8
|
to manage the versions of this gem so
|
9
9
|
that you can set version constraints properly.
|
10
10
|
|
11
|
-
#### [Unreleased](https://github.com/exAspArk/batch-loader/compare/v1.1.
|
11
|
+
#### [Unreleased](https://github.com/exAspArk/batch-loader/compare/v1.1.1...HEAD)
|
12
12
|
|
13
13
|
* WIP
|
14
14
|
|
15
|
+
#### [v1.1.1](https://github.com/exAspArk/batch-loader/compare/v1.1.0...v1.1.1)
|
16
|
+
|
17
|
+
* `Fixed`: `loader`, made it thread-safe again. [#10](https://github.com/exAspArk/batch-loader/pull/10)
|
18
|
+
|
15
19
|
#### [v1.1.0](https://github.com/exAspArk/batch-loader/compare/v1.0.4...v1.1.0)
|
16
20
|
|
17
21
|
* `Added`: `default_value` override option. [#8](https://github.com/exAspArk/batch-loader/pull/8)
|
data/lib/batch_loader.rb
CHANGED
@@ -18,8 +18,9 @@ class BatchLoader
|
|
18
18
|
new(item: item)
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(item:)
|
21
|
+
def initialize(item:, executor_proxy: nil)
|
22
22
|
@item = item
|
23
|
+
@__executor_proxy = executor_proxy
|
23
24
|
end
|
24
25
|
|
25
26
|
def batch(default_value: nil, cache: true, &batch_block)
|
@@ -76,23 +77,29 @@ class BatchLoader
|
|
76
77
|
return if __executor_proxy.value_loaded?(item: @item)
|
77
78
|
|
78
79
|
items = __executor_proxy.list_items
|
79
|
-
loader =
|
80
|
+
loader = __loader
|
81
|
+
@batch_block.call(items, loader)
|
82
|
+
items.each do |item|
|
83
|
+
next if __executor_proxy.value_loaded?(item: item)
|
84
|
+
loader.call(item, @default_value)
|
85
|
+
end
|
86
|
+
__executor_proxy.delete(items: items)
|
87
|
+
end
|
88
|
+
|
89
|
+
def __loader
|
90
|
+
mutex = Mutex.new
|
91
|
+
-> (item, value = (no_value = true; nil), &block) do
|
80
92
|
if no_value && !block
|
81
93
|
raise ArgumentError, "Please pass a value or a block"
|
82
94
|
elsif block && !no_value
|
83
95
|
raise ArgumentError, "Please pass a value or a block, not both"
|
84
96
|
end
|
85
97
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@batch_block.call(items, loader)
|
91
|
-
items.each do |item|
|
92
|
-
next if __executor_proxy.value_loaded?(item: item)
|
93
|
-
loader.call(item, @default_value)
|
98
|
+
mutex.synchronize do
|
99
|
+
next_value = block ? block.call(__executor_proxy.loaded_value(item: item)) : value
|
100
|
+
__executor_proxy.load(item: item, value: next_value)
|
101
|
+
end
|
94
102
|
end
|
95
|
-
__executor_proxy.delete(items: items)
|
96
103
|
end
|
97
104
|
|
98
105
|
def __singleton_class
|
data/lib/batch_loader/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batch-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- exAspArk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|