Class: Wukong::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/wukong/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataflow) ⇒ Driver

Returns a new instance of Driver.



68
69
70
# File 'lib/wukong/driver.rb', line 68

def initialize(dataflow)
  @dataflow = dataflow
end

Instance Attribute Details

#dataflowObject

Returns the value of attribute dataflow.



66
67
68
# File 'lib/wukong/driver.rb', line 66

def dataflow
  @dataflow
end

Instance Method Details

#advance(stage) ⇒ Object



87
88
89
90
# File 'lib/wukong/driver.rb', line 87

def advance(stage)
  next_stage = stage_iterator(stage)
  start_with(next_stage)
end

#call(*args) ⇒ Object



98
99
100
# File 'lib/wukong/driver.rb', line 98

def call(*args)
  to_proc.call(*args)
end

#send_through_dataflow(record) ⇒ Object



79
80
81
# File 'lib/wukong/driver.rb', line 79

def send_through_dataflow(record)
  start_with(dataflow.first).call(record)
end

#stage_iterator(stage) ⇒ Object

This should properly be defined on dataflow/builder



93
94
95
96
# File 'lib/wukong/driver.rb', line 93

def stage_iterator(stage)
  position = dataflow.find_index(stage)
  dataflow[position + 1]    
end

#start_with(stage) ⇒ Object



83
84
85
# File 'lib/wukong/driver.rb', line 83

def start_with(stage)
  to_proc.curry.call(stage)
end

#to_procObject



72
73
74
75
76
77
# File 'lib/wukong/driver.rb', line 72

def to_proc
  return @wiring if @wiring
  @wiring = Proc.new do |stage, record|
    stage.process(record, &advance(stage)) if stage          
  end
end