Module: Adhearsion::Events

Defined in:
lib/adhearsion/events.rb

Defined Under Namespace

Classes: Handler, Worker

Class Method Summary collapse

Class Method Details

.clearObject


81
82
83
84
# File 'lib/adhearsion/events.rb', line 81

def clear
  @queue = nil
  Handler.instance.clear_handlers
end

.draw(&block) ⇒ Object


58
59
60
# File 'lib/adhearsion/events.rb', line 58

def draw(&block)
  Handler.instance.instance_exec(&block)
end

.initObject


70
71
72
73
74
# File 'lib/adhearsion/events.rb', line 70

def init
  size = Adhearsion.config.core.event_threads
  logger.debug "Initializing event worker pool of size #{size}"
  @queue = Worker.pool(size: size)
end

.method_missing(method_name, *args, &block) ⇒ Object


42
43
44
# File 'lib/adhearsion/events.rb', line 42

def method_missing(method_name, *args, &block)
  Handler.instance.send method_name, *args, &block
end

.queueObject


62
63
64
65
66
67
68
# File 'lib/adhearsion/events.rb', line 62

def queue
  unless @queue && @queue.alive?
    init
  end

  @queue
end

.refresh!Object


76
77
78
79
# File 'lib/adhearsion/events.rb', line 76

def refresh!
  clear
  init
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/adhearsion/events.rb', line 46

def respond_to_missing?(method_name, include_private = false)
  Handler.instance.respond_to? method_name, include_private
end

.trigger(type, object = nil) ⇒ Object


50
51
52
# File 'lib/adhearsion/events.rb', line 50

def trigger(type, object = nil)
  queue.async.work type, object
end

.trigger_immediately(type, object = nil) ⇒ Object


54
55
56
# File 'lib/adhearsion/events.rb', line 54

def trigger_immediately(type, object = nil)
  queue.work type, object
end