Class: Stepladder::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/stepladder/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p = {}, &block) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
10
11
12
13
14
# File 'lib/stepladder/worker.rb', line 5

def initialize(p={}, &block)
  @supplier = p[:supplier]
  @filter   = p[:filter] || default_filter
  @task     = block || p[:task]
  # don't define default task here
  # because we want to allow for
  # an initialized worker to have
  # a task injected, including
  # method-based tasks.
end

Instance Attribute Details

#supplierObject

Returns the value of attribute supplier.



3
4
5
# File 'lib/stepladder/worker.rb', line 3

def supplier
  @supplier
end

Instance Method Details

#productObject



16
17
18
19
# File 'lib/stepladder/worker.rb', line 16

def product
  ensure_ready_to_work!
  workflow.resume
end

#ready_to_work?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/stepladder/worker.rb', line 21

def ready_to_work?
  @task && (supplier || !task_accepts_a_value?)
end

#|(subscribing_worker) ⇒ Object



25
26
27
28
# File 'lib/stepladder/worker.rb', line 25

def |(subscribing_worker)
  subscribing_worker.supplier = self
  subscribing_worker
end