slow_enumerator_tools 1.0.0a1
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 +7 -0
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.rubocop.yml +58 -0
- data/.travis.yml +18 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/NEWS.md +5 -0
- data/README.md +118 -0
- data/Rakefile +11 -0
- data/lib/slow_enumerator_tools.rb +15 -0
- data/lib/slow_enumerator_tools/bufferer.rb +49 -0
- data/lib/slow_enumerator_tools/merger.rb +59 -0
- data/lib/slow_enumerator_tools/version.rb +5 -0
- data/scripts/release +95 -0
- data/slow_enumerator_tools.gemspec +19 -0
- data/spec/bufferer_spec.rb +37 -0
- data/spec/merger_spec.rb +70 -0
- data/spec/slow_enumerator_tools_spec.rb +17 -0
- data/spec/spec_helper.rb +11 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33dc358ef4d7c116477605b28b24a83c6a9f902a
|
4
|
+
data.tar.gz: 91ac07dd9c7f7ed253c80aa3a638ba600cb2c0a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 395e9429d2ddddf3367cb2ff35d64b1f0d5456ffad14f7c41e0679206c9c4a85fb7a46b93af08d14088755c22cd693d8c0b7b302f59c2e2c7e852615a0828685
|
7
|
+
data.tar.gz: 92b0eaf5eef204f3612f1069e8c8c7facdbcb6f468b542a9516d0042c5d84dd22f84b203e8e525a2434caf34db84e07d3ca3726526bc52622fcbf48fd63af8e8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# ----- CONFIGURED -----
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
DisplayCopNames: true
|
6
|
+
|
7
|
+
Style/TrailingCommaInArguments:
|
8
|
+
EnforcedStyleForMultiline: comma
|
9
|
+
|
10
|
+
Style/TrailingCommaInLiteral:
|
11
|
+
EnforcedStyleForMultiline: comma
|
12
|
+
|
13
|
+
Layout/IndentArray:
|
14
|
+
EnforcedStyle: consistent
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
# ----- DISABLED (metrics) -----
|
19
|
+
|
20
|
+
# Cops for metrics are disabled because they should not cause tests to fail.
|
21
|
+
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/BlockLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/BlockNesting:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/CyclomaticComplexity:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metrics/LineLength:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/MethodLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Metrics/ModuleLength:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Metrics/ParameterLists:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/PerceivedComplexity:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
# ----- DISABLED (opinionated) -----
|
55
|
+
|
56
|
+
# It does not make sense to enforce everything to have documentation.
|
57
|
+
Style/Documentation:
|
58
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at denis.defreyne@stoneship.org. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Denis Defreyne
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/NEWS.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
[](http://rubygems.org/gems/slow_enumerator_tools)
|
2
|
+
[](http://rubygems.org/gems/slow_enumerator_tools)
|
3
|
+
[](https://travis-ci.org/ddfreyne/slow_enumerator_tools)
|
4
|
+
[](https://codeclimate.com/github/ddfreyne/slow_enumerator_tools)
|
5
|
+
[](https://codecov.io/gh/ddfreyne/slow_enumerator_tools)
|
6
|
+
|
7
|
+
# SlowEnumeratorTools
|
8
|
+
|
9
|
+
_SlowEnumeratorTools_ provides tools for transforming Ruby enumerators that produce data slowly and unpredictably (e.g. from a network source):
|
10
|
+
|
11
|
+
* `SlowEnumeratorTools.merge`: given a collection of enumerables, creates a new enumerator that yields elements from any of these enumerables as soon as they become available.
|
12
|
+
|
13
|
+
* `SlowEnumeratorTools.buffer`: given an enumerable, creates a new enumerable that yields batches containing all elements currently available.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'slow_enumerator_tools'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install slow_enumerator_tools
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### `SlowEnumeratorTools.merge`
|
34
|
+
|
35
|
+
Given a collection of enumerables, creates a new enumerator that yields elements from any of these enumerables as soon as they become available.
|
36
|
+
|
37
|
+
This is useful for combining multiple event streams into a single one.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Generate some slow enums
|
41
|
+
enums = []
|
42
|
+
enums << 5.times.lazy.map { |i| sleep(0.1 + rand * 0.2); [:a, i] }
|
43
|
+
enums << 5.times.lazy.map { |i| sleep(0.1 + rand * 0.2); [:b, i] }
|
44
|
+
enums << 5.times.lazy.map { |i| sleep(0.1 + rand * 0.2); [:c, i] }
|
45
|
+
|
46
|
+
# Merge and print
|
47
|
+
merged_enum = SlowEnumeratorTools.merge(enums)
|
48
|
+
merged_enum.each { |e| p e }
|
49
|
+
```
|
50
|
+
|
51
|
+
Example output:
|
52
|
+
|
53
|
+
```
|
54
|
+
[:b, 0]
|
55
|
+
[:a, 0]
|
56
|
+
[:b, 1]
|
57
|
+
[:c, 0]
|
58
|
+
[:a, 1]
|
59
|
+
[:b, 2]
|
60
|
+
[:c, 1]
|
61
|
+
[:c, 2]
|
62
|
+
[:a, 2]
|
63
|
+
[:b, 3]
|
64
|
+
[:c, 3]
|
65
|
+
[:b, 4]
|
66
|
+
[:a, 3]
|
67
|
+
[:c, 4]
|
68
|
+
[:a, 4]
|
69
|
+
```
|
70
|
+
|
71
|
+
### `SlowEnumeratorTools.buffer`
|
72
|
+
|
73
|
+
Given an enumerable, creates a new enumerable that yields batches containing all elements currently available.
|
74
|
+
|
75
|
+
This is useful for fetching all outstanding events on an event stream, without blocking.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# Generate a slow enum
|
79
|
+
enum = 4.times.lazy.map { |i| sleep(0.1); i }
|
80
|
+
|
81
|
+
# Buffer
|
82
|
+
buffer_enum = SlowEnumeratorTools.buffer(enum)
|
83
|
+
|
84
|
+
# Wait until first batch is available
|
85
|
+
# … prints [0]
|
86
|
+
p buffer_enum.next
|
87
|
+
|
88
|
+
# Give it enough time for the second batch to have accumulated more elements,
|
89
|
+
# … prints [1, 2]
|
90
|
+
sleep 0.25
|
91
|
+
p buffer_enum.next
|
92
|
+
|
93
|
+
# Wait until final batch is available
|
94
|
+
# … prints [3]
|
95
|
+
p buffer_enum.next
|
96
|
+
```
|
97
|
+
|
98
|
+
## Development
|
99
|
+
|
100
|
+
Install dependencies:
|
101
|
+
|
102
|
+
$ bundle
|
103
|
+
|
104
|
+
Run tests:
|
105
|
+
|
106
|
+
$ bundle exec rake
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slow_enumerator_tools. 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.
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
115
|
+
|
116
|
+
## Code of Conduct
|
117
|
+
|
118
|
+
Everyone interacting in the SlowEnumeratorTools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/slow_enumerator_tools/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlowEnumeratorTools
|
4
|
+
def self.merge(es)
|
5
|
+
SlowEnumeratorTools::Merger.merge(es)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.buffer(es)
|
9
|
+
SlowEnumeratorTools::Bufferer.buffer(es)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative 'slow_enumerator_tools/version'
|
14
|
+
require_relative 'slow_enumerator_tools/bufferer'
|
15
|
+
require_relative 'slow_enumerator_tools/merger'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlowEnumeratorTools
|
4
|
+
module Bufferer
|
5
|
+
def self.buffer(enum)
|
6
|
+
q = Queue.new
|
7
|
+
stop = Object.new
|
8
|
+
|
9
|
+
t =
|
10
|
+
Thread.new do
|
11
|
+
enum.each do |e|
|
12
|
+
q << e
|
13
|
+
end
|
14
|
+
q << stop
|
15
|
+
end
|
16
|
+
|
17
|
+
Enumerator.new do |y|
|
18
|
+
loop do
|
19
|
+
res = []
|
20
|
+
ended = false
|
21
|
+
|
22
|
+
# pop first
|
23
|
+
elem = q.pop
|
24
|
+
break if stop.equal?(elem)
|
25
|
+
res << elem
|
26
|
+
|
27
|
+
loop do
|
28
|
+
# pop remaining
|
29
|
+
begin
|
30
|
+
elem = q.pop(true)
|
31
|
+
rescue ThreadError
|
32
|
+
break
|
33
|
+
end
|
34
|
+
if stop.equal?(elem)
|
35
|
+
ended = true
|
36
|
+
break
|
37
|
+
end
|
38
|
+
res << elem
|
39
|
+
end
|
40
|
+
|
41
|
+
y << res
|
42
|
+
break if ended
|
43
|
+
end
|
44
|
+
|
45
|
+
t.join
|
46
|
+
end.lazy
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlowEnumeratorTools
|
4
|
+
module Merger
|
5
|
+
def self.merge(enums)
|
6
|
+
enum = Iterator.new(enums).tap(&:start)
|
7
|
+
|
8
|
+
Enumerator.new do |y|
|
9
|
+
loop { y << enum.next }
|
10
|
+
end.lazy
|
11
|
+
end
|
12
|
+
|
13
|
+
class Iterator
|
14
|
+
DONE = Object.new
|
15
|
+
|
16
|
+
def initialize(enums)
|
17
|
+
@enums = enums
|
18
|
+
@q = SizedQueue.new(5)
|
19
|
+
@done = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def next
|
23
|
+
raise StopIteration if @done
|
24
|
+
|
25
|
+
nxt = @q.pop
|
26
|
+
if DONE.equal?(nxt)
|
27
|
+
@done = true
|
28
|
+
raise StopIteration
|
29
|
+
else
|
30
|
+
nxt
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
threads = @enums.map { |enum| spawn_empty_into(enum, @q) }
|
36
|
+
|
37
|
+
spawn do
|
38
|
+
threads.each(&:join)
|
39
|
+
@q << DONE
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def spawn_empty_into(enum, queue)
|
46
|
+
spawn do
|
47
|
+
enum.each { |e| queue << e }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def spawn
|
52
|
+
Thread.new do
|
53
|
+
Thread.current.abort_on_exception = true
|
54
|
+
yield
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/scripts/release
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'octokit'
|
6
|
+
|
7
|
+
def run(*args)
|
8
|
+
puts 'I will execute the following:'
|
9
|
+
puts ' ' + args.map { |a| a =~ /\s/ ? a.inspect : a }.join(' ')
|
10
|
+
print 'Is this correct? [y/N] '
|
11
|
+
res = gets
|
12
|
+
unless res.strip.casecmp('y').zero?
|
13
|
+
$stderr.puts 'Answer was not Y; release aborted.'
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
system('echo', *args)
|
18
|
+
system(*args)
|
19
|
+
|
20
|
+
print 'Continue? [y/N] '
|
21
|
+
res = gets
|
22
|
+
unless res.strip.casecmp('y').zero?
|
23
|
+
$stderr.puts 'Answer was not Y; release aborted.'
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
puts '=== Logging in to GitHub’s API…'
|
29
|
+
client = Octokit::Client.new(netrc: true)
|
30
|
+
puts
|
31
|
+
|
32
|
+
puts '=== Deleting old *.gem files…'
|
33
|
+
Dir['*.gem'].each do |fn|
|
34
|
+
puts " #{fn}…"
|
35
|
+
FileUtils.rm_f(fn)
|
36
|
+
end
|
37
|
+
puts
|
38
|
+
|
39
|
+
puts '=== Verifying presence of release date…'
|
40
|
+
unless File.readlines('NEWS.md').drop(2).first =~ / \(\d{4}-\d{2}-\d{2}\)$/
|
41
|
+
$stderr.puts 'No proper release date found!'
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
puts
|
45
|
+
|
46
|
+
puts '=== Building new gem…'
|
47
|
+
run('gem', 'build', 'slow_enumerator_tools.gemspec')
|
48
|
+
puts
|
49
|
+
|
50
|
+
puts '=== Reading version…'
|
51
|
+
require './lib/slow_enumerator_tools/version'
|
52
|
+
puts "Version = #{SlowEnumeratorTools::VERSION}"
|
53
|
+
puts
|
54
|
+
|
55
|
+
puts '=== Verifying that release does not yet exist…'
|
56
|
+
releases = client.releases('ddfreyne/slow_enumerator_tools')
|
57
|
+
release = releases.find { |r| r.tag_name == SlowEnumeratorTools::VERSION }
|
58
|
+
if release
|
59
|
+
$stderr.puts 'Release already exists!'
|
60
|
+
$stderr.puts 'ABORTED!'
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
puts
|
64
|
+
|
65
|
+
puts '=== Creating Git tag…'
|
66
|
+
run('git', 'tag', '--sign', '--annotate', SlowEnumeratorTools::VERSION, '--message', "Version #{SlowEnumeratorTools::VERSION}")
|
67
|
+
puts
|
68
|
+
|
69
|
+
puts '=== Pushing Git data…'
|
70
|
+
run('git', 'push', 'origin', '--tags')
|
71
|
+
puts
|
72
|
+
|
73
|
+
puts '=== Pushing gem…'
|
74
|
+
run('gem', 'push', "slow_enumerator_tools-#{SlowEnumeratorTools::VERSION}.gem")
|
75
|
+
puts
|
76
|
+
|
77
|
+
puts '=== Reading release notes…'
|
78
|
+
release_notes =
|
79
|
+
File.readlines('NEWS.md')
|
80
|
+
.drop(4)
|
81
|
+
.take_while { |l| l !~ /^## / }
|
82
|
+
.join
|
83
|
+
puts
|
84
|
+
|
85
|
+
puts '=== Creating release on GitHub…'
|
86
|
+
sleep 3 # Give GitHub some time to detect the new tag
|
87
|
+
is_prerelease = SlowEnumeratorTools::VERSION =~ /a|b|rc/ || SlowEnumeratorTools::VERSION =~ /^0/
|
88
|
+
client.create_release(
|
89
|
+
'ddfreyne/slow_enumerator_tools', SlowEnumeratorTools::VERSION,
|
90
|
+
prerelease: !is_prerelease.nil?,
|
91
|
+
body: release_notes
|
92
|
+
)
|
93
|
+
puts
|
94
|
+
|
95
|
+
puts 'DONE!'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/slow_enumerator_tools/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'slow_enumerator_tools'
|
7
|
+
spec.version = SlowEnumeratorTools::VERSION
|
8
|
+
spec.authors = ['Denis Defreyne']
|
9
|
+
spec.email = ['denis.defreyne@stoneship.org']
|
10
|
+
|
11
|
+
spec.summary = 'provides tools for transforming Ruby enumerators that produce data slowly and unpredictably'
|
12
|
+
spec.homepage = 'https://github.com/ddfreyne/slow_enumerator_tools'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SlowEnumeratorTools::Bufferer do
|
4
|
+
let(:wrapped) do
|
5
|
+
Enumerator.new do |y|
|
6
|
+
5.times do |i|
|
7
|
+
y << i
|
8
|
+
sleep 0.2
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject do
|
14
|
+
described_class.buffer(wrapped)
|
15
|
+
end
|
16
|
+
|
17
|
+
example do
|
18
|
+
expect(subject.next).to eq([0])
|
19
|
+
end
|
20
|
+
|
21
|
+
example do
|
22
|
+
subject.next
|
23
|
+
expect(subject.next).to eq([1])
|
24
|
+
end
|
25
|
+
|
26
|
+
example do
|
27
|
+
subject
|
28
|
+
sleep 0.25
|
29
|
+
expect(subject.next).to eq([0, 1])
|
30
|
+
end
|
31
|
+
|
32
|
+
example do
|
33
|
+
subject
|
34
|
+
sleep 0.45
|
35
|
+
expect(subject.next).to eq([0, 1, 2])
|
36
|
+
end
|
37
|
+
end
|
data/spec/merger_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SlowEnumeratorTools::Merger do
|
4
|
+
subject { described_class.merge(enums).to_a }
|
5
|
+
|
6
|
+
context 'no enums' do
|
7
|
+
let(:enums) { [] }
|
8
|
+
it { is_expected.to be_empty }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'one enum, empty' do
|
12
|
+
let(:enums) { [[]] }
|
13
|
+
it { is_expected.to be_empty }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'one enum, one element' do
|
17
|
+
let(:enums) { [[1]] }
|
18
|
+
it { is_expected.to eq([1]) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'one enum, two elements' do
|
22
|
+
let(:enums) { [[1, 2]] }
|
23
|
+
it { is_expected.to eq([1, 2]) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'two enums, empty + empty' do
|
27
|
+
let(:enums) { [[], []] }
|
28
|
+
it { is_expected.to be_empty }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'two enums, empty + one el' do
|
32
|
+
let(:enums) { [[], [1]] }
|
33
|
+
it { is_expected.to eq([1]) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'two enums, empty + two el' do
|
37
|
+
let(:enums) { [[], [1, 2]] }
|
38
|
+
it { is_expected.to eq([1, 2]) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'two enums, one el + empty' do
|
42
|
+
let(:enums) { [[1], []] }
|
43
|
+
it { is_expected.to match_array([1]) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'two enums, one el + one el' do
|
47
|
+
let(:enums) { [[1], [2]] }
|
48
|
+
it { is_expected.to match_array([1, 2]) }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'two enums, one el + two el' do
|
52
|
+
let(:enums) { [[1], [2, 3]] }
|
53
|
+
it { is_expected.to match_array([1, 2, 3]) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'two enums, two el + empty' do
|
57
|
+
let(:enums) { [[1, 2], []] }
|
58
|
+
it { is_expected.to match_array([1, 2]) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'two enums, two el + one el' do
|
62
|
+
let(:enums) { [[1, 2], [3]] }
|
63
|
+
it { is_expected.to match_array([1, 2, 3]) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'two enums, two el + two el' do
|
67
|
+
let(:enums) { [[1, 2], [3, 4]] }
|
68
|
+
it { is_expected.to match_array([1, 2, 3, 4]) }
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SlowEnumeratorTools do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(SlowEnumeratorTools::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'supports .merge shorthand' do
|
9
|
+
expect(SlowEnumeratorTools.merge([[1, 2], [3, 4]]).to_a)
|
10
|
+
.to match_array([1, 2, 3, 4])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'supports .buffer shorthand' do
|
14
|
+
expect(SlowEnumeratorTools.buffer([1, 2]).to_a)
|
15
|
+
.to match_array([[1, 2]])
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slow_enumerator_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0a1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Defreyne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- denis.defreyne@stoneship.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".travis.yml"
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- NEWS.md
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/slow_enumerator_tools.rb
|
45
|
+
- lib/slow_enumerator_tools/bufferer.rb
|
46
|
+
- lib/slow_enumerator_tools/merger.rb
|
47
|
+
- lib/slow_enumerator_tools/version.rb
|
48
|
+
- scripts/release
|
49
|
+
- slow_enumerator_tools.gemspec
|
50
|
+
- spec/bufferer_spec.rb
|
51
|
+
- spec/merger_spec.rb
|
52
|
+
- spec/slow_enumerator_tools_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/ddfreyne/slow_enumerator_tools
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.3.1
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.6.13
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: provides tools for transforming Ruby enumerators that produce data slowly
|
78
|
+
and unpredictably
|
79
|
+
test_files: []
|