lib/shifty/dsl.rb in shifty-0.4.1 vs lib/shifty/dsl.rb in shifty-0.4.2

- old
+ new

@@ -8,11 +8,11 @@ series = series_from(argument) callable = setup_callable_for(block, series) return Worker.new(&callable) if series.nil? - Worker.new do + Worker.new(tags: [:source]) do series.each(&callable) loop do handoff nil end @@ -20,21 +20,21 @@ end def relay_worker(&block) ensure_regular_arity(block) - Worker.new do |value| + Worker.new(tags: [:relay]) do |value| value && block.call(value) end end def side_worker(mode = :normal, &block) ensure_regular_arity(block) Worker.new(tags: [:side_effect]) do |value| value.tap do |v| - used_value = mode == :hardened ? + used_value = (mode == :hardened) ? Marshal.load(Marshal.dump(v)) : v v && block.call(used_value) end end @@ -45,11 +45,11 @@ throw_with "You cannot supply two callables" end callable = argument.respond_to?(:call) ? argument : block ensure_callable(callable) - Worker.new do |value, supply| + Worker.new(tags: [:filter]) do |value, supply| while value && !callable.call(value) value = supply.shift end value end @@ -67,11 +67,11 @@ batch_full = block || proc { |_, batch| batch.size >= options[:gathering] } batch_context = BatchContext.new({batch_full: batch_full}) - Worker.new(context: batch_context) do |value, supply, context| + Worker.new(tags: [:batch], context: batch_context) do |value, supply, context| if value context.collection = [value] until context.batch_complete?( context.collection.last, context.collection @@ -84,11 +84,11 @@ end def splitter_worker(&block) ensure_regular_arity(block) - Worker.new do |value| + Worker.new(tags: [:splitter]) do |value| if value.nil? value else parts = [block.call(value)].flatten while parts.size > 1 @@ -99,10 +99,10 @@ end end def trailing_worker(trail_length = 2) trail = [] - Worker.new do |value, supply| + Worker.new(tags: [:trailing]) do |value, supply| if value trail.unshift value if trail.size >= trail_length trail.pop end