Class: FluQ::Worker
- Inherits:
-
Object
- Object
- FluQ::Worker
- Includes:
- Celluloid, Mixins::Loggable
- Defined in:
- lib/fluq/worker.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#add(klass, *args) ⇒ Object
Adds a handler.
-
#initialize(prefix, handlers = []) ⇒ Worker
constructor
A new instance of Worker.
- #process(events) ⇒ Object
Methods included from Mixins::Loggable
Constructor Details
#initialize(prefix, handlers = []) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 16 17 |
# File 'lib/fluq/worker.rb', line 9 def initialize(prefix, handlers = []) @prefix = prefix @handlers = [] @observer = observe handlers.each do |klass, *args| add klass, *args end end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
6 7 8 |
# File 'lib/fluq/worker.rb', line 6 def handlers @handlers end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/fluq/worker.rb', line 6 def prefix @prefix end |
Instance Method Details
#add(klass, *args) ⇒ Object
Adds a handler
31 32 33 34 35 |
# File 'lib/fluq/worker.rb', line 31 def add(klass, *args) handler = klass.new(*args) handlers.push handler handler end |
#process(events) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/fluq/worker.rb', line 20 def process(events) events.freeze # Freeze events, don't allow individual handlers to modify them handlers.each do |handler| on_events(handler, Time.now, events) end true end |