Class: Shifty::Worker

Inherits:
Object
  • Object
show all
Includes:
Taggable
Defined in:
lib/shifty/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Taggable

#criteria=, #criteria_passes?, #has_tag?, #tags=

Constructor Details

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

Returns a new instance of Worker.



10
11
12
13
14
15
16
# File 'lib/shifty/worker.rb', line 10

def initialize(p = {}, &block)
  @supply       = p[:supply]
  @task         = block || p[:task]
  @context      = p[:context] || OpenStruct.new
  self.criteria = p[:criteria]
  self.tags     = p[:tags]
end

Instance Attribute Details

#supplyObject

Returns the value of attribute supply.



6
7
8
# File 'lib/shifty/worker.rb', line 6

def supply
  @supply
end

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/shifty/worker.rb', line 6

def tags
  @tags
end

Instance Method Details

#ready_to_work?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/shifty/worker.rb', line 23

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

#shiftObject



18
19
20
21
# File 'lib/shifty/worker.rb', line 18

def shift
  ensure_ready_to_work!
  workflow.resume
end

#suppliable?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/shifty/worker.rb', line 38

def suppliable?
  @task && @task.arity > 0
end

#supplies(subscribing_worker) ⇒ Object Also known as: |



27
28
29
30
# File 'lib/shifty/worker.rb', line 27

def supplies(subscribing_worker)
  subscribing_worker.supply = self
  subscribing_worker
end