batches 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d6ca29db1c0da3a1ff3d969a9eeb91f5cb0f3e2b
4
- data.tar.gz: e537430c0aec395cd2f1344c0b4a1da141c3e7ef
2
+ SHA256:
3
+ metadata.gz: 4af89b1db30d354712b15e647bfa67d1f431e7d0068aa5722f38a36504b3a0bd
4
+ data.tar.gz: d47f9a6cb369edd1d44c6d97518c1b2b2ae464871ee3c1571c4dc26053b9a11a
5
5
  SHA512:
6
- metadata.gz: 90ccb38764f7bd5d229b02193bd688ffca83eceb1c25aca03a05fb300e04e3540e2c3939e6bcc5cffb1a6f48272e2304c0c1a7aee019cbf1309d588befe01503
7
- data.tar.gz: e73e246343944382b5ae5a4f575ec3b02faa175002df8d53cd16559c17df1c80e49eb1dac443a93d24016f18b62ffcf0cbd71b37ac74a22945c8d4caea1d26cb
6
+ metadata.gz: 6acdbe923ebbd9aff2f9bcd868d93991c738d9e13c118e441287ffbc12242f53f8e3a45ebcbd2f3d78cdd84b810f3f74ec9615f44969d4df845ae25f3f880492
7
+ data.tar.gz: d15daf9c08e90e8488d25e831eb554bf993860846a994ec5f16d435d44b79f51def74e88ee0ea0da88f7dbc6794e71f992b9aa0238e00540bb041301f17e5fb8
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Batches
2
2
 
3
- TODO: Write a gem description
3
+ A simple wrapper of multithreading in Ruby
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,11 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Handling the entity array in 20 threads
22
+
23
+ require 'batches'
24
+ Batches.do(20, entities) do |entity|
25
+ do_some_thing_with(entity)
26
+ end
22
27
 
23
28
  ## Contributing
24
29
 
25
- 1. Fork it ( https://github.com/[my-github-username]/batches/fork )
30
+ 1. Fork it ( https://github.com/Slacken/batches/fork )
26
31
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
32
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
33
  4. Push to the branch (`git push origin my-new-feature`)
@@ -4,15 +4,12 @@ class Batches
4
4
  class NoBlockError < ArgumentError; end
5
5
 
6
6
  def self.do(cocurrence, entities, &block)
7
- raise NoBlockError, "No block given" unless block
8
- entities.each_slice(cocurrence) do |group|
9
- threads = []
10
- group.each do |entity|
11
- threads << Thread.new(entity) do |ent|
12
- block.call(ent)
13
- end
7
+ raise NoBlockError, "No block given" if block.nil?
8
+ entities.each_slice(cocurrence).map do |group|
9
+ threads = group.map do |entity|
10
+ Thread.new(entity){|e| block.call(e) }
14
11
  end
15
- threads.each{|thread| thread.join}
16
- end
12
+ threads.map{|t| t.value }
13
+ end.flatten(1)
17
14
  end
18
15
  end
@@ -1,3 +1,3 @@
1
1
  class Batches
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batches
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - binz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.2.2
77
+ rubygems_version: 2.6.14
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: A simple wrapper of <cocurrence> threads to process <entities>