Class: RMExtensions::EventsToProxy
- Inherits:
-
Object
- Object
- RMExtensions::EventsToProxy
- Defined in:
- lib/motion/events.rb
Overview
Proxy object used to hold the firing objects that this real object’s “self” owns handlers for. Can be used to cleanup all handlers across all firing objects that have the hanlder’s owner (Proc#owner) == this real object. Does not need to perform deallocation logic as nothing is retained and the real object will fall out of the cooresponding EventsFromProxy automatically.
Instance Method Summary collapse
- #cleanup(firing_object = nil) ⇒ Object
- #has_handlers_for!(firing_object) ⇒ Object
-
#initialize(obj) ⇒ EventsToProxy
constructor
A new instance of EventsToProxy.
Constructor Details
#initialize(obj) ⇒ EventsToProxy
Returns a new instance of EventsToProxy.
82 83 84 85 |
# File 'lib/motion/events.rb', line 82 def initialize(obj) self.weak_object = obj @has_handlers_for = NSHashTable.weakObjectsHashTable end |
Instance Method Details
#cleanup(firing_object = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/motion/events.rb', line 94 def cleanup(firing_object=nil) # p "cleanup caller", caller if firing_object if @has_handlers_for.containsObject(firing_object) if ::RMExtensions.debug? p "CONTEXT:", weak_object.rmext_object_desc, "UNLISTENING TO:", firing_object.rmext_object_desc end @has_handlers_for.removeObject(firing_object) firing_object.rmext_off(weak_object) end else while firing_object = @has_handlers_for.anyObject if ::RMExtensions.debug? p "CONTEXT:", weak_object.rmext_object_desc, "UNLISTENING TO:", firing_object.rmext_object_desc end @has_handlers_for.removeObject(firing_object) firing_object.rmext_off(weak_object) end end true end |
#has_handlers_for!(firing_object) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/motion/events.rb', line 87 def has_handlers_for!(firing_object) if ::RMExtensions.debug? p "CONTEXT:", weak_object.rmext_object_desc, "LISTENING TO:", firing_object.rmext_object_desc end @has_handlers_for.addObject(firing_object) end |