Class: Pigeon::Processor
- Inherits:
-
Object
- Object
- Pigeon::Processor
- Defined in:
- lib/pigeon/processor.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Properties ===========================================================.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
-
#accept?(task) ⇒ Boolean
Returns true if the given task would be accepted by the filter defined for this processor.
-
#initialize(queue = nil, context = nil, &filter) ⇒ Processor
constructor
Creates a new processor.
- #inspect ⇒ Object
-
#task? ⇒ Boolean
Returns true if a task is currently being processed, false otherwise.
Constructor Details
#initialize(queue = nil, context = nil, &filter) ⇒ Processor
Creates a new processor. An optional queue can be specified in which case the processor will register itself as an observer of that queue. A block can be given to filter the tasks contained in the associated queue.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pigeon/processor.rb', line 20 def initialize(queue = nil, context = nil, &filter) @id = Pigeon::Support.unique_id @filter = filter @context = context @task = nil if (queue) self.queue = queue switch_to_next_task! end end |
Instance Attribute Details
#context ⇒ Object
Properties ===========================================================
8 9 10 |
# File 'lib/pigeon/processor.rb', line 8 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/pigeon/processor.rb', line 11 def id @id end |
#queue ⇒ Object
Returns the value of attribute queue.
9 10 11 |
# File 'lib/pigeon/processor.rb', line 9 def queue @queue end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
10 11 12 |
# File 'lib/pigeon/processor.rb', line 10 def task @task end |
Instance Method Details
#accept?(task) ⇒ Boolean
Returns true if the given task would be accepted by the filter defined for this processor.
59 60 61 |
# File 'lib/pigeon/processor.rb', line 59 def accept?(task) !@filter or @filter.call(task) end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/pigeon/processor.rb', line 68 def inspect "<#{self.class}\##{@id} queue=#{@queue.inspect} task=#{@task} context=#{@context}>" end |
#task? ⇒ Boolean
Returns true if a task is currently being processed, false otherwise.
64 65 66 |
# File 'lib/pigeon/processor.rb', line 64 def task? !!@task end |