Class: Adhearsion::Events
- Inherits:
-
Object
show all
- Includes:
- HasGuardedHandlers
- Defined in:
- lib/adhearsion/events.rb
Defined Under Namespace
Classes: Message
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_name, *args, &block)
66
67
68
|
# File 'lib/adhearsion/events.rb', line 66
def method_missing(method_name, *args, &block)
register_handler method_name, *args, &block
end
|
Class Method Details
+ (Object) instance
19
20
21
|
# File 'lib/adhearsion/events.rb', line 19
def instance
@@instance || refresh!
end
|
+ (Object) method_missing(method_name, *args, &block)
11
12
13
|
# File 'lib/adhearsion/events.rb', line 11
def method_missing(method_name, *args, &block)
instance.send method_name, *args, &block
end
|
+ (Object) refresh!
23
24
25
|
# File 'lib/adhearsion/events.rb', line 23
def refresh!
@@instance = new
end
|
+ (Boolean) respond_to?(method_name)
15
16
17
|
# File 'lib/adhearsion/events.rb', line 15
def respond_to?(method_name)
instance.respond_to?(method_name) || super
end
|
Instance Method Details
- (Object) draw(&block)
62
63
64
|
# File 'lib/adhearsion/events.rb', line 62
def draw(&block)
instance_exec(&block)
end
|
- (Object) handle_message(message)
58
59
60
|
# File 'lib/adhearsion/events.rb', line 58
def handle_message(message)
trigger_handler message.type, message.object
end
|
30
31
32
|
# File 'lib/adhearsion/events.rb', line 30
def queue
queue? ? @queue : reinitialize_queue!
end
|
- (Boolean) queue?
42
43
44
|
# File 'lib/adhearsion/events.rb', line 42
def queue?
instance_variable_defined? :@queue
end
|
- (Object) reinitialize_queue!
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/adhearsion/events.rb', line 46
def reinitialize_queue!
GirlFriday.shutdown! if queue?
@queue = GirlFriday::WorkQueue.new 'main_queue', :error_handler => ErrorHandler do |message|
begin
handle_message message
rescue Exception => e
ErrorHandler.new.handle e
end
end
end
|
- (Boolean) respond_to?(method_name)
70
71
72
73
|
# File 'lib/adhearsion/events.rb', line 70
def respond_to?(method_name)
return true if instance_variable_defined?(:@handlers) && @handlers.has_key?(method_name)
super
end
|
- (Object) trigger(type, object = nil)
34
35
36
|
# File 'lib/adhearsion/events.rb', line 34
def trigger(type, object = nil)
queue.push_async Message.new(type, object)
end
|
38
39
40
|
# File 'lib/adhearsion/events.rb', line 38
def trigger_immediately(type, object = nil)
queue.push_immediately Message.new(type, object)
end
|