Module: Listener

Included in:
Smagacor::UndoManager
Defined in:
lib/smagacor/listener.rb

Instance Method Summary collapse

Instance Method Details

#add_msg_listener(msgName, callableObject = nil, &block) ⇒ Object

Adds a new message listener for the object. The message msgName will be dispatched to either the given callableObject (has to respond to call) or the given block. If both are specified the callableObject is used.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/smagacor/listener.rb', line 7

def add_msg_listener( msgName, callableObject = nil, &block )
  return unless defined?( @msgNames ) && @msgNames.has_key?( msgName )

  if !callableObject.nil?
    raise NoMethodError, "listener needs to respond to 'call'" unless callableObject.respond_to? :call
    @msgNames[msgName].push callableObject
  elsif !block.nil?
    @msgNames[msgName].push block
  else
    raise "you have to provide a callback object or a block"
  end
end

#del_msg_listener(msgName, object) ⇒ Object

Removes the given object from the dispatcher queue of the message msgName.



21
22
23
# File 'lib/smagacor/listener.rb', line 21

def del_msg_listener( msgName, object )
  @msgNames[msgName].delete object if defined? @msgNames
end