Class: Rad::Conveyors::Conveyor

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/conveyors/_conveyor.rb

Instance Method Summary collapse

Instance Method Details

#build!Object



12
13
14
15
16
17
18
# File 'lib/rad/conveyors/_conveyor.rb', line 12

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



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

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

#definitionsObject



4
5
6
# File 'lib/rad/conveyors/_conveyor.rb', line 4

def definitions
  @definitions ||= []
end

#inspectObject



38
39
40
# File 'lib/rad/conveyors/_conveyor.rb', line 38

def inspect
  definitions.inspect
end

#use(processor_class, *initialization_arguments) ⇒ Object



8
9
10
# File 'lib/rad/conveyors/_conveyor.rb', line 8

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