Class: Triton::Messenger::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/triton/messenger.rb

Overview

The Listener class helps managing event triggering. It may not be used as its own.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, callback, once = false) ⇒ Listener

Returns a new instance of Listener.



86
87
88
89
90
# File 'lib/triton/messenger.rb', line 86

def initialize(type, callback, once=false)
  @type = type
  @callback = callback
  @once = once
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



84
85
86
# File 'lib/triton/messenger.rb', line 84

def callback
  @callback
end

#onceObject

Returns the value of attribute once.



84
85
86
# File 'lib/triton/messenger.rb', line 84

def once
  @once
end

#typeObject

Returns the value of attribute type.



84
85
86
# File 'lib/triton/messenger.rb', line 84

def type
  @type
end

Instance Method Details

#fire(sender = nil, *args) ⇒ Object

Call the event listener passing through the sender and the additional args



93
94
95
96
97
98
99
# File 'lib/triton/messenger.rb', line 93

def fire(sender=nil, *args)
  @callback.call(sender, *args)

  if @once
    Messenger::remove_listener(self)
  end
end