rm-extensions 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -6,6 +6,9 @@ Extensions and helpers for dealing with various areas of rubymotion:
6
6
  - block/scope/local variable issues
7
7
  - GCD blocks
8
8
  - retaining objects through async procedures
9
+ - weak attr_accessors
10
+
11
+ Currently depends on bubblewrap and BlocksKit.
9
12
 
10
13
  ## Installation
11
14
 
@@ -13,13 +16,17 @@ Add this line to your application's Gemfile:
13
16
 
14
17
  gem 'rm-extensions'
15
18
 
19
+ Add this line to your application's Rakefile:
20
+
21
+ pod 'BlocksKit'
22
+
16
23
  And then execute:
17
24
 
18
25
  $ bundle
19
26
 
20
27
  ## Usage
21
28
 
22
- Read through the commented code.
29
+ Some code is commented. TODO.
23
30
 
24
31
  ## Contributing
25
32
 
@@ -5,18 +5,27 @@ module RMExtensions
5
5
 
6
6
  def rmext_weak_attr_accessor(*attrs)
7
7
  attrs.each do |attr|
8
+ ptr = Pointer.new(:object)
9
+ ptr.assign(attr.to_sym)
8
10
  define_method(attr) do
9
- if val = instance_variable_get("@#{attr}")
10
- val.nonretainedObjectValue
11
- end
11
+ associatedValueForKey(ptr)
12
12
  end
13
13
  define_method("#{attr}=") do |val|
14
- if val.nil?
15
- instance_variable_set("@#{attr}", nil)
16
- else
17
- # should we do an rmext_on_dealloc on the val?
18
- instance_variable_set("@#{attr}", NSValue.valueWithNonretainedObject(val))
19
- end
14
+ weaklyAssociateValue(val, withKey:ptr)
15
+ val
16
+ end
17
+ end
18
+ end
19
+
20
+ def rmext_copy_attr_accessor(*attrs)
21
+ attrs.each do |attr|
22
+ ptr = Pointer.new(:object)
23
+ ptr.assign(attr.to_sym)
24
+ define_method(attr) do
25
+ associatedValueForKey(ptr)
26
+ end
27
+ define_method("#{attr}=") do |val|
28
+ associateCopyOfValue(val, withKey:ptr)
20
29
  val
21
30
  end
22
31
  end
@@ -157,8 +166,7 @@ module RMExtensions
157
166
  end
158
167
 
159
168
  def rmext_on_dealloc(&block)
160
- internalObject = ::RMExtensions::OnDeallocInternalObject.create(&block)
161
- internalObject.obj = self
169
+ internalObject = ::RMExtensions::OnDeallocInternalObject.create("#{self.class.name}:#{object_id}", self, block)
162
170
  @rmext_on_dealloc_blocks ||= {}
163
171
  @rmext_on_dealloc_blocks[internalObject] = internalObject
164
172
  nil
@@ -316,14 +324,17 @@ module RMExtensions
316
324
  end
317
325
 
318
326
  class OnDeallocInternalObject
319
- attr_accessor :block
327
+ attr_accessor :description, :block
320
328
  rmext_weak_attr_accessor :obj
321
- def self.create(&block)
329
+ def self.create(description, obj, block)
322
330
  x = new
331
+ x.description = description
332
+ x.obj = obj
323
333
  x.block = block
324
334
  x
325
335
  end
326
336
  def dealloc
337
+ # p "dealloc OnDeallocInternalObject #{description}"
327
338
  if block
328
339
  block.call(obj)
329
340
  self.block = nil
@@ -1,3 +1,3 @@
1
1
  module RMExtensions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rm-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: