class Marso::Enumerate
Constants
- STOP_MSG
Attributes
process[R]
src[R]
Public Class Methods
from(collection)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 9 def self.from(collection) _process = lambda { collection.each { |x| Fiber.yield x } raise StopIteration, STOP_MSG } Enumerate.new(_process) end
new(process, source={})
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 21 def initialize(process, source={}) @src = source @process = process @fiber_delegate = Fiber.new do process.call end end
Public Instance Methods
clone()
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 42 def clone class_name = self.class.to_s if @src.is_a?(Marso::Enumerate) return Object.const_get(class_name).new(@process, @src.clone) else return Object.const_get(class_name).new(@process) end end
execute(max_iteration=1000000)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 67 def execute(max_iteration=1000000) begin if max_iteration.zero? loop do self.resume end else max_iteration.times { self.resume } end rescue StopIteration => ex raise ex unless ex.message == STOP_MSG rescue Exception => ex raise ex end end
resume()
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 30 def resume if @src.is_a?(Marso::Enumerate) @fiber_delegate.resume(@src.resume) else # case where @src is nil @fiber_delegate.resume end end
select(&block)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 59 def select(&block) FiberProjection.new(block, clone_original_source_to_protect_it) end
select_many(&block)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 63 def select_many(&block) FiberProjectionMany.new(block, clone_original_source_to_protect_it) end
source(other_source)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 38 def source(other_source) Enumerate.new(@process, other_source) end
to_a()
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 83 def to_a a = [] begin loop do a << self.resume end rescue StopIteration => ex raise ex unless ex.message == STOP_MSG rescue Exception => ex raise ex end return a end
where(&block)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 55 def where(&block) FiberFilter.new(block, clone_original_source_to_protect_it) end
|(other_source)
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 51 def |(other_source) other_source.source(clone_original_source_to_protect_it) end
Private Instance Methods
clone_original_source_to_protect_it()
click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 99 def clone_original_source_to_protect_it # prevent the core source to be altered so that we can reuse it # to build other queries. Otherwise, after one usage, there'll be # a dead fiber exception thrown return self.clone end