Class: Alondra::ListenerCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/alondra/listener_callback.rb

Constant Summary collapse

CHANNEL_NAME_PATTERN =
%r{\d+$}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type, options = {}, proc) ⇒ ListenerCallback

Returns a new instance of ListenerCallback.



9
10
11
12
13
# File 'lib/alondra/listener_callback.rb', line 9

def initialize(event_type, options = {}, proc)
  @event_type = event_type
  @options    = options
  @proc       = proc
end

Instance Attribute Details

#event_typeObject (readonly)

Returns the value of attribute event_type.



3
4
5
# File 'lib/alondra/listener_callback.rb', line 3

def event_type
  @event_type
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/alondra/listener_callback.rb', line 4

def options
  @options
end

#procObject (readonly)

Returns the value of attribute proc.



5
6
7
# File 'lib/alondra/listener_callback.rb', line 5

def proc
  @proc
end

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/alondra/listener_callback.rb', line 15

def matches?(event)
  return false unless event.type == event_type

  case options[:to]
  when nil then true
  when :member then
    member_channel? event.channel_name
  when :collection then
    !member_channel?(event.channel_name)
  end
end

#to_procObject



27
28
29
# File 'lib/alondra/listener_callback.rb', line 27

def to_proc
  proc
end