Class: Moon::Eventable::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/std/mixins/eventable.rb

Overview

Structure for holding event listener information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, filter, callback) ⇒ Listener

Returns a new instance of Listener.

Parameters:

  • type (Class)
  • filter (Proc)
  • callback (callback)

24
25
26
# File 'lib/moon/packages/std/mixins/eventable.rb', line 24

def initialize(type, filter, callback)
  @type, @filter, @callback = type, filter, callback
end

Instance Attribute Details

#callbackProc

Returns function to call when the Event is triggered.

Returns:

  • (Proc)

    function to call when the Event is triggered


19
20
21
# File 'lib/moon/packages/std/mixins/eventable.rb', line 19

def callback
  @callback
end

#filterProc

Returns used to determine if the event is valid.

Returns:

  • (Proc)

    used to determine if the event is valid.


15
16
17
# File 'lib/moon/packages/std/mixins/eventable.rb', line 15

def filter
  @filter
end

#typeClass, Symbol

Returns type.

Returns:


11
12
13
# File 'lib/moon/packages/std/mixins/eventable.rb', line 11

def type
  @type
end

Instance Method Details

#invoke(event, obj) ⇒ Object


28
29
30
31
# File 'lib/moon/packages/std/mixins/eventable.rb', line 28

def invoke(event, obj)
  return unless @filter.call(event)
  @callback.call(event, obj)
end