ddbuffer 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 +5 -5
- data/NEWS.md +4 -0
- data/README.md +5 -44
- data/ddbuffer.gemspec +1 -0
- data/lib/ddbuffer.rb +3 -37
- data/lib/ddbuffer/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaa9bbb025759cb2843a1958a0a145ba5e6fd14970b12077da0eef7bfc0fc7e5
|
4
|
+
data.tar.gz: 29a34a8d792e38b08d23e70b36f4d3f9fff5ae193bf3192c98a35cd943a8cf84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512e43cb24a634a925ad4bcab5f81ecf515025d03b293d642a9bb250981fcafdd2c077f8a558eff1fb373f69d43366fc149e9866ca490452d80802a45f615c71
|
7
|
+
data.tar.gz: c1ef5243c60cecd9de8fe06187fed2678498be28e546828846b571a9db6138c8ce7cd016c87c95c842757f83c2213f91d5e96081805733ed3aaded99900f2d7c
|
data/NEWS.md
CHANGED
data/README.md
CHANGED
@@ -1,54 +1,15 @@
|
|
1
|
-
[![Gem version](http://img.shields.io/gem/v/ddbuffer.svg)](http://rubygems.org/gems/ddbuffer)
|
2
|
-
[![Build status](http://img.shields.io/travis/ddfreyne/ddbuffer.svg)](https://travis-ci.org/ddfreyne/ddbuffer)
|
3
|
-
[![Code Climate](http://img.shields.io/codeclimate/github/ddfreyne/ddbuffer.svg)](https://codeclimate.com/github/ddfreyne/ddbuffer)
|
4
|
-
[![Code Coverage](https://img.shields.io/codecov/c/github/ddfreyne/ddbuffer.svg)](https://codecov.io/gh/ddfreyne/ddbuffer)
|
5
|
-
|
6
1
|
# DDBuffer
|
7
2
|
|
8
|
-
|
3
|
+
**Deprecated** in favor of [slow_enumerator_tools](https://github.com/ddfreyne/slow_enumerator_tools).
|
9
4
|
|
10
|
-
|
5
|
+
Replace
|
11
6
|
|
12
7
|
```ruby
|
13
|
-
|
14
|
-
articles = my_web_service.each_article
|
15
|
-
|
16
|
-
# Buffer 100 articles at a time
|
17
|
-
articles = DDBuffer.new(100).call(articles)
|
18
|
-
|
19
|
-
# Write buffered articles
|
20
|
-
articles.each_slice(50) do |slice|
|
21
|
-
my_slow_db.insert_articles(slice)
|
22
|
-
end
|
8
|
+
DDBuffer.new(size).call(enum)
|
23
9
|
```
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
To install, add the `ddbuffer` gem to your Gemfile, and run `bundle`.
|
28
|
-
|
29
|
-
To buffer an enumerable `enum` with a buffer size of `size`:
|
11
|
+
with
|
30
12
|
|
31
13
|
```ruby
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
## Development
|
36
|
-
|
37
|
-
To run the tests:
|
38
|
-
|
39
|
-
```
|
40
|
-
bundle install
|
41
|
-
bundle exec rake
|
14
|
+
SlowEnumeratorTools.buffer(enum, size)
|
42
15
|
```
|
43
|
-
|
44
|
-
## Contributing
|
45
|
-
|
46
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ddfreyne/ddbuffer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
47
|
-
|
48
|
-
## License
|
49
|
-
|
50
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
-
|
52
|
-
## Code of Conduct
|
53
|
-
|
54
|
-
Everyone interacting in the DDBuffer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ddfreyne/ddbuffer/blob/master/CODE_OF_CONDUCT.md).
|
data/ddbuffer.gemspec
CHANGED
data/lib/ddbuffer.rb
CHANGED
@@ -2,48 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'ddbuffer/version'
|
4
4
|
|
5
|
-
|
6
|
-
module Impl
|
7
|
-
STOP_OK = Object.new
|
8
|
-
STOP_ERR = Object.new
|
9
|
-
|
10
|
-
def self.gen_collector_thread(enum, queue)
|
11
|
-
Thread.new do
|
12
|
-
begin
|
13
|
-
enum.each { |e| queue << e }
|
14
|
-
queue << STOP_OK
|
15
|
-
rescue StandardError => e
|
16
|
-
queue << STOP_ERR
|
17
|
-
queue << e
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.gen_enumerator(queue, collector_thread)
|
23
|
-
Enumerator.new do |y|
|
24
|
-
loop do
|
25
|
-
e = queue.pop
|
26
|
-
|
27
|
-
if STOP_OK.equal?(e)
|
28
|
-
break
|
29
|
-
elsif STOP_ERR.equal?(e)
|
30
|
-
raise queue.pop
|
31
|
-
end
|
32
|
-
|
33
|
-
y << e
|
34
|
-
end
|
35
|
-
collector_thread.join
|
36
|
-
end.lazy
|
37
|
-
end
|
38
|
-
end
|
5
|
+
require 'slow_enumerator_tools'
|
39
6
|
|
7
|
+
class DDBuffer
|
40
8
|
def initialize(size)
|
41
9
|
@size = size
|
42
10
|
end
|
43
11
|
|
44
12
|
def call(enum)
|
45
|
-
|
46
|
-
thread = Impl.gen_collector_thread(enum, queue)
|
47
|
-
Impl.gen_enumerator(queue, thread)
|
13
|
+
SlowEnumeratorTools.buffer(enum, @size)
|
48
14
|
end
|
49
15
|
end
|
data/lib/ddbuffer/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddbuffer
|
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
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slow_enumerator_tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
81
|
version: '0'
|
68
82
|
requirements: []
|
69
83
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.7.1
|
71
85
|
signing_key:
|
72
86
|
specification_version: 4
|
73
87
|
summary: Buffer enumerables
|