lib/adhearsion/events.rb in adhearsion-2.0.0.beta1 vs lib/adhearsion/events.rb in adhearsion-2.0.0.rc1
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: utf-8
+
module Adhearsion
class Events
include HasGuardedHandlers
@@ -24,23 +26,27 @@
end
refresh!
def queue
- @queue || reinitialize_queue!
+ queue? ? @queue : reinitialize_queue!
end
def trigger(type, object = nil)
queue.push_async Message.new(type, object)
end
def trigger_immediately(type, object = nil)
queue.push_immediately Message.new(type, object)
end
+ def queue?
+ instance_variable_defined? :@queue
+ end
+
def reinitialize_queue!
- GirlFriday.shutdown! if @queue
+ GirlFriday.shutdown! if queue?
# TODO: Extract number of threads to use from Adhearsion.config
@queue = GirlFriday::WorkQueue.new 'main_queue', :error_handler => ErrorHandler do |message|
begin
handle_message message
rescue Exception => e
@@ -52,18 +58,18 @@
def handle_message(message)
trigger_handler message.type, message.object
end
def draw(&block)
- instance_exec &block
+ instance_exec(&block)
end
def method_missing(method_name, *args, &block)
register_handler method_name, *args, &block
end
def respond_to?(method_name)
- return true if @handlers && @handlers.has_key?(method_name)
+ return true if instance_variable_defined?(:@handlers) && @handlers.has_key?(method_name)
super
end
alias :register_callback :register_handler