lib/tresse.rb in tresse-1.0.0 vs lib/tresse.rb in tresse-1.1.0
- old
+ new
@@ -2,11 +2,11 @@
require 'thread'
module Tresse
- VERSION = '1.0.0'
+ VERSION = '1.1.0'
class << self
def init
@@ -81,10 +81,16 @@
end
#
self.init
+ def self.call_block(block, args)
+
+ block.call(*args[0, block.method(:call).arity.abs])
+ end
+
+
class Batch
attr_reader :group
attr_reader :map_index
attr_accessor :value
@@ -104,23 +110,17 @@
@group.send(:receive, self)
end
def source
- args = [ group ] + [ nil ] * 7
- args = args[0, @bog.method(:call).arity]
-
- @value = @bog.call(*args)
+ @value = Tresse.call_block(@bog, [ group ] + [ nil ] * 7)
end
def map(type, block)
- args = [ @value, self ]
- args = args[0, block.method(:call).arity.abs]
+ r = Tresse.call_block(block, [ @value, self ])
- r = block.call(*args)
-
@value = r if type == :map
end
end
class Group
@@ -147,9 +147,22 @@
def source(o=nil, &block)
batch = Tresse::Batch.new(self, o ? o : block)
@batches << batch
+
+ self
+ end
+
+ def source_each(collection, &block)
+
+ if collection.is_a?(Array)
+ collection.each_with_index { |e, i|
+ source { Tresse.call_block(block, [ e, i ]) } }
+ else
+ collection.each { |k, v|
+ source { Tresse.call_block(block, [ k, v ]) } }
+ end
self
end
#