rm-extensions 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/motion/observation.rb +8 -10
- data/lib/motion/util.rb +17 -0
- data/lib/rm-extensions.rb +0 -1
- data/lib/rm-extensions/version.rb +1 -1
- metadata +2 -3
- data/lib/motion/deallocation.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbf506f0e146d719368d97d86a04b4fede0df97b
|
4
|
+
data.tar.gz: 6d8b171e1add24ee6c63d27ee4057c6051f944a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3204fde1f0f0e9c903aa2fdda8a638f4c91544e2a81b404b728eb9bd100200ce8c81fa5d69cc6d2a57002a1182d968d331b8164e629fa30227b6f426e2ccdb18
|
7
|
+
data.tar.gz: 8fc6a988442c02b7ba501b7c360a1825d20ed40899b6707d3d4b179cb8e51c865f2552ab59357ea0a64368341a3345be2918aabdb7dc0f9f618c6ca11fcb825c
|
data/CHANGELOG.md
CHANGED
data/lib/motion/observation.rb
CHANGED
@@ -83,9 +83,6 @@ module RMExtensions
|
|
83
83
|
DEFAULT_OPTIONS = NSKeyValueObservingOptionNew
|
84
84
|
|
85
85
|
def initialize(obj)
|
86
|
-
obj.rmext_on_dealloc do |x|
|
87
|
-
cleanup
|
88
|
-
end
|
89
86
|
@desc = obj.inspect
|
90
87
|
@events = {}
|
91
88
|
@targets = {}
|
@@ -96,6 +93,7 @@ module RMExtensions
|
|
96
93
|
|
97
94
|
def dealloc
|
98
95
|
@did_dealloc = true
|
96
|
+
cleanup
|
99
97
|
if ::RMExtensions.debug?
|
100
98
|
p "dealloc ObservationProxy for #{@desc}"
|
101
99
|
end
|
@@ -127,7 +125,7 @@ module RMExtensions
|
|
127
125
|
|
128
126
|
key_paths = @targets[target]
|
129
127
|
if !key_paths.nil? && key_paths.has_key?(key_path.to_s)
|
130
|
-
key_paths.
|
128
|
+
key_paths.removeObject(key_path.to_s)
|
131
129
|
end
|
132
130
|
end
|
133
131
|
|
@@ -142,7 +140,7 @@ module RMExtensions
|
|
142
140
|
target.removeObserver(self, forKeyPath:key_path)
|
143
141
|
end
|
144
142
|
end
|
145
|
-
@targets.
|
143
|
+
@targets.removeAllObjects
|
146
144
|
end
|
147
145
|
|
148
146
|
def registered?(target, key_path)
|
@@ -152,8 +150,8 @@ module RMExtensions
|
|
152
150
|
def add_observer_block(target, key_path, &block)
|
153
151
|
return if target.nil? || key_path.nil? || block.nil?
|
154
152
|
@targets[target] ||= {}
|
155
|
-
@targets[target][key_path.to_s] ||=
|
156
|
-
@targets[target][key_path.to_s]
|
153
|
+
@targets[target][key_path.to_s] ||= NSHashTable.weakObjectsHashTable
|
154
|
+
@targets[target][key_path.to_s].addObject block
|
157
155
|
end
|
158
156
|
|
159
157
|
# NSKeyValueObserving Protocol
|
@@ -179,17 +177,17 @@ module RMExtensions
|
|
179
177
|
def on(event, &block)
|
180
178
|
return if event.nil? || block.nil?
|
181
179
|
@events[event.to_s] ||= []
|
182
|
-
@events[event.to_s]
|
180
|
+
@events[event.to_s].addObject block
|
183
181
|
end
|
184
182
|
|
185
183
|
def off(event, &block)
|
186
184
|
return if event.nil? || block.nil? || !@events.key?(event.to_s)
|
187
|
-
@events[event.to_s].
|
185
|
+
@events[event.to_s].removeObject block
|
188
186
|
nil
|
189
187
|
end
|
190
188
|
|
191
189
|
def off_all
|
192
|
-
@events.
|
190
|
+
@events.removeAllObjects
|
193
191
|
end
|
194
192
|
|
195
193
|
def trigger(event, *args)
|
data/lib/motion/util.rb
CHANGED
@@ -31,6 +31,23 @@ module RMExtensions
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def rmext_nil_instance_variables!
|
35
|
+
ivars = [] + instance_variables
|
36
|
+
while ivar = ivars.pop
|
37
|
+
instance_variable_set(ivar, nil)
|
38
|
+
end
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def rmext_assign_debug_labels_to_ivars!
|
43
|
+
ivars = [] + instance_variables
|
44
|
+
while ivar = ivars.pop
|
45
|
+
val = instance_variable_get(ivar)
|
46
|
+
val.rmext_ivar(:debug_label, ivar)
|
47
|
+
end
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
34
51
|
end
|
35
52
|
|
36
53
|
end
|
data/lib/rm-extensions.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rm-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Noon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extensions and helpers for dealing with various areas of rubymotion
|
14
14
|
email:
|
@@ -25,7 +25,6 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- app/app_delegate.rb
|
27
27
|
- lib/motion/accessors.rb
|
28
|
-
- lib/motion/deallocation.rb
|
29
28
|
- lib/motion/layout.rb
|
30
29
|
- lib/motion/observation.rb
|
31
30
|
- lib/motion/queues.rb
|
data/lib/motion/deallocation.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module RMExtensions
|
2
|
-
|
3
|
-
module ObjectExtensions
|
4
|
-
|
5
|
-
module Deallocation
|
6
|
-
|
7
|
-
# perform a block before +self+ will dealloc.
|
8
|
-
# the block given should have one argument, the object about to be deallocated.
|
9
|
-
def rmext_on_dealloc(&block)
|
10
|
-
internalObject = ::RMExtensions::OnDeallocInternalObject.create("#{self.class.name}:#{object_id}", self, block)
|
11
|
-
@rmext_on_dealloc_blocks ||= {}
|
12
|
-
@rmext_on_dealloc_blocks[internalObject] = internalObject
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# removes a previously added block from the deallocation callback list
|
17
|
-
def rmext_cancel_on_dealloc(block)
|
18
|
-
@rmext_on_dealloc_blocks ||= {}
|
19
|
-
if internalObject = @rmext_on_dealloc_blocks[block]
|
20
|
-
internalObject.block = nil
|
21
|
-
@rmext_on_dealloc_blocks.delete(block)
|
22
|
-
end
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
# Used internally by +rmext_on_dealloc+. The idea is this object is added to the
|
31
|
-
# object we want to watch for deallocation. When the object we want to watch
|
32
|
-
# is about to dealloc, this object will dealloc first, so we can execute the block.
|
33
|
-
# the object it follows is kept only as a weak reference to not create
|
34
|
-
# a retain cycle.
|
35
|
-
class OnDeallocInternalObject
|
36
|
-
attr_accessor :description, :block
|
37
|
-
rmext_weak_attr_accessor :obj
|
38
|
-
def self.create(description, obj, block)
|
39
|
-
x = new
|
40
|
-
x.description = description
|
41
|
-
x.obj = obj
|
42
|
-
x.block = block
|
43
|
-
x
|
44
|
-
end
|
45
|
-
def dealloc
|
46
|
-
# p "dealloc OnDeallocInternalObject #{description}"
|
47
|
-
if block
|
48
|
-
block.call(obj)
|
49
|
-
self.block = nil
|
50
|
-
end
|
51
|
-
super
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
Object.send(:include, ::RMExtensions::ObjectExtensions::Deallocation)
|