Class: Crystal::Conveyor

Inherits:
Object show all
Defined in:
lib/crystal/conveyor/conveyor.rb

Instance Method Summary collapse

Instance Method Details

#build!Object



13
14
15
16
17
18
19
# File 'lib/crystal/conveyor/conveyor.rb', line 13

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

#call(workspace_content = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/crystal/conveyor/conveyor.rb', line 21

def call workspace_content = {}, &block
  build! unless @chain
  
  crystal.activate :cycle, {} do        
    self.workspace = Workspace.new
    workspace.merge! workspace_content 
    
    if block
      block.call{@chain.call}
    else
      @chain.call
    end
    
    workspace
  end
end

#definitionsObject



5
6
7
# File 'lib/crystal/conveyor/conveyor.rb', line 5

def definitions
  @definitions ||= []
end

#inspectObject



38
39
40
# File 'lib/crystal/conveyor/conveyor.rb', line 38

def inspect
  definitions.inspect
end

#use(processor_class, *initialization_arguments) ⇒ Object



9
10
11
# File 'lib/crystal/conveyor/conveyor.rb', line 9

def use processor_class, *initialization_arguments
  definitions << [processor_class, initialization_arguments]
end