Sha256: 89debbe6351b484e5b94b59ee4d153184aa20e7e975227b70167eedb5e3245b9

Contents?: true

Size: 1.77 KB

Versions: 24

Compression:

Stored size: 1.77 KB

Contents

class Rad::Conveyors::Conveyor
  inject workspace: :workspace

  def definitions
    @definitions ||= []
  end
    
  def use processor_class, *initialization_arguments
    definitions << [processor_class, initialization_arguments]
  end

  def build!
    @chain = lambda{}      
    definitions.reverse.collect do |klass, args| 
      klass.must_be.a Class
      @chain = klass.new @chain, *args
    end
  end

  def call workspace_content = {}, &block
    build! unless @chain
  
    scope = (rad.custom_scopes[:cycle] || {}).clone
    rad.activate :cycle, scope do
      self.workspace = ::Rad::Conveyors::Workspace.new unless self.workspace?
      workspace.merge! workspace_content 
    
      if block
        block.call(@chain)
      else
        @chain.call
      end
    
      workspace
    end
  end

  def inspect
    definitions.inspect
  end

  # def trace name, &block
  #   start_time = Time.now
  #   block.call
  #   (workspace.trace ||= []) << [name, Time.now - start_time]
  # end       

  protected
    # def build_chain
    #   next_processor_call = nil
    #   chain = reverse.collect do |processor|
    #     next_processor_call = if next_processor_call
    #       lambda{processor.call next_processor}
    #     else
    #       lambda{processor.call lambda{}}
    #     end
    #   end
    #   next_processor_call
    # end


  # def add_before key, *processors
  #   index = index{|processor| processor.name == key or processor.class == key}
  #   raise "Can't find Processor '#{name}'!" unless index
  #   insert index, *Array(processors)
  # end
  # 
  # def add_after key, *processors
  #   index = rindex{|processor| processor.name == key or processor.class == key}
  #   raise "Can't find Processor '#{name}'!" unless index
  #   insert index + 1, *Array(processors)
  # end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.5 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.4 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.3 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.2 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.1 lib/rad/conveyors/_conveyor.rb
rad_core-0.2.0 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.30 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.29 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.28 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.27 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.26 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.25 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.24 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.23 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.22 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.21 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.20 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.19 lib/rad/conveyors/_conveyor.rb
rad_core-0.0.18 lib/rad/conveyors/_conveyor.rb