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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10b3c8d7d655d2182fc655af633cafccabdfe460
4
- data.tar.gz: 064e5f501609992377c5579cb398dd2db2c26e37
3
+ metadata.gz: cbf506f0e146d719368d97d86a04b4fede0df97b
4
+ data.tar.gz: 6d8b171e1add24ee6c63d27ee4057c6051f944a4
5
5
  SHA512:
6
- metadata.gz: ac1bc79b513e9b0adbafe309a3c6e795883c05b34eca599af6a730cf37cfdec82a2cda180b74137a41cb5a14e4a13098a3b5df49fb7fb2c80884c94a2d059ecf
7
- data.tar.gz: 0ae909d56376adfd984be7dcbbbb4e36e26b5e39b093881040e4e261e71ffd8e7fb37d18286dda5d1e0f8025e7cce55cc6a3b36e01e96499f5a39a24b33a124d
6
+ metadata.gz: 3204fde1f0f0e9c903aa2fdda8a638f4c91544e2a81b404b728eb9bd100200ce8c81fa5d69cc6d2a57002a1182d968d331b8164e629fa30227b6f426e2ccdb18
7
+ data.tar.gz: 8fc6a988442c02b7ba501b7c360a1825d20ed40899b6707d3d4b179cb8e51c865f2552ab59357ea0a64368341a3345be2918aabdb7dc0f9f618c6ca11fcb825c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ [Commit history](https://github.com/joenoon/rm-extensions/compare/v0.1.10...v0.2.0)
4
+
5
+ * Experimental changes. Changelog to move to wiki soon.
6
+
1
7
  ## 0.1.10
2
8
 
3
9
  [Commit history](https://github.com/joenoon/rm-extensions/compare/v0.1.9...v0.1.10)
@@ -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.delete(key_path.to_s)
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.clear
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] << block
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] << block
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].delete_if { |b| b == block }
185
+ @events[event.to_s].removeObject block
188
186
  nil
189
187
  end
190
188
 
191
189
  def off_all
192
- @events.clear
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
@@ -9,7 +9,6 @@ Motion::Project::App.setup do |app|
9
9
  layout
10
10
  util
11
11
  accessors
12
- deallocation
13
12
  observation
14
13
  queues
15
14
  ).reverse.each do |x|
@@ -1,3 +1,3 @@
1
1
  module RMExtensions
2
- VERSION = "0.1.10"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.10
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-09-15 00:00:00.000000000 Z
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
@@ -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)