Class: Shifty::Worker
Instance Attribute Summary collapse
-
#supply ⇒ Object
Returns the value of attribute supply.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(p = {}, &block) ⇒ Worker
constructor
A new instance of Worker.
- #ready_to_work? ⇒ Boolean
- #shift ⇒ Object
- #suppliable? ⇒ Boolean
- #supplies(subscribing_worker) ⇒ Object (also: #|)
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. = p[:tags] end |
Instance Attribute Details
#supply ⇒ Object
Returns the value of attribute supply.
6 7 8 |
# File 'lib/shifty/worker.rb', line 6 def supply @supply end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/shifty/worker.rb', line 6 def @tags end |
Instance Method Details
#ready_to_work? ⇒ Boolean
23 24 25 |
# File 'lib/shifty/worker.rb', line 23 def ready_to_work? @task && (supply || !task_accepts_a_value?) end |
#shift ⇒ Object
18 19 20 21 |
# File 'lib/shifty/worker.rb', line 18 def shift ensure_ready_to_work! workflow.resume end |
#suppliable? ⇒ 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 |