Module: Contrails::Chainable

Included in:
Parallel, Process, Serial
Defined in:
lib/contrails/chainable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
18
# File 'lib/contrails/chainable.rb', line 15

def self.included(base)
  base.extend(ClassMethods)
  base.send(:include, EventMachine::Deferrable)
end

Instance Method Details

#*(other) ⇒ Object



47
48
49
# File 'lib/contrails/chainable.rb', line 47

def *(other)
  self.distribute(other)
end

#>>(other) ⇒ Object



43
44
45
# File 'lib/contrails/chainable.rb', line 43

def >>(other)
  self.bind(other)
end

#bind(other) ⇒ Object



20
21
22
23
# File 'lib/contrails/chainable.rb', line 20

def bind(other)
  require 'contrails/serial'
  Serial.new(self, other)
end

#call(*a) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/contrails/chainable.rb', line 30

def call(*a)
  result = run(*a)
  if result.is_a?(Array)  #This is ugly, but we have to do it to get around the fact that
    self.succeed(*result) #splat (*) operator will decompose structs too, which we don't want.
  else
    self.succeed(result)
  end
end

#distribute(other) ⇒ Object



25
26
27
28
# File 'lib/contrails/chainable.rb', line 25

def distribute(other)
  require 'contrails/parallel'
  Parallel.new(self, other)
end

#runObject

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/contrails/chainable.rb', line 5

def run
  raise NotImplementedError
end

#to_procObject



39
40
41
# File 'lib/contrails/chainable.rb', line 39

def to_proc
  lambda {|*a| self.call(*a) }
end