Module: CelluloidIOPGListener::Initialization::AsyncListener

Defined in:
lib/celluloid-io-pg-listener/initialization/async_listener.rb

Instance Method Summary collapse

Instance Method Details

#callback_methodObject



32
33
34
# File 'lib/celluloid-io-pg-listener/initialization/async_listener.rb', line 32

def callback_method
  @callback_method
end

#initialize(*args) ⇒ Object

2nd initialize override invoked



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/celluloid-io-pg-listener/initialization/async_listener.rb', line 9

def initialize(*args)
  hash_arg = args.last.is_a?(Hash) ? args.pop : {}
  warn "[#{self.class}] You have not specified a callback_method, so :unlisten_wrapper will be used." unless hash_arg[:callback_method]
  @callback_method = hash_arg.delete(:callback_method) || :unlisten_wrapper
  # Doesn't appear to be any other way to make it work with subclassing,
  #   due to the way Celluloid Proxies the class, and hijacks the inheritance chains
  subclassed_client = hash_arg.delete(:subclassed_client) || false
  args << hash_arg unless hash_arg.empty?

  enhance_callback_method unless @callback_method == :unlisten_wrapper

  # When called from a sub-class of a class including Client
  #   and the sub-class overrides initialize,
  #   then the execution order changes,
  #   and this method may no longer have a super.
  # However, due to the nature of the initialize method we can't tell if we have a legitimate super or not.
  super(*args) if !subclassed_client

  debug "Listening for notifications on #{dbname}:#{channel} with callback to #{@callback_method}"
  async.start_listening
  async.listen(channel, @callback_method)
end