Module: Tinker::Evented
Instance Method Summary collapse
-
#dispatch(event) ⇒ Object
Internal: Disatches an event.
- #every(time, *callbacks, &block) ⇒ Object
- #on(event_name, *callbacks, &block) ⇒ Object
Instance Method Details
#dispatch(event) ⇒ Object
26 27 28 29 30 |
# File 'lib/tinker/evented.rb', line 26 def dispatch(event) _dispatchers[event.name].each do |callback| event_callback event, callback end end |
#every(time, *callbacks, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tinker/evented.rb', line 8 def every(time, *callbacks, &block) callbacks << block if block EventMachine.add_periodic_timer(time) do env = Tinker::Event::Environment.new(nil, self) event = Tinker::Event.new("meta.timer.tick", env) callbacks.each do |callback| event_callback(event, callback) end end end |
#on(event_name, *callbacks, &block) ⇒ Object
2 3 4 5 6 |
# File 'lib/tinker/evented.rb', line 2 def on(event_name, *callbacks, &block) raise ArgumentError, 'No callbacks given' unless callbacks.any? || block _dispatchers[event_name].push(*callbacks) if callbacks.any? _dispatchers[event_name].push(&block) if block end |