motion-weakattr 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b1d25fd3c31dc3c22a17c87d851d19c5d177428
4
+ data.tar.gz: 108710e2e4dfa34c43b7ce0cada1ffc3b7246d5c
5
+ SHA512:
6
+ metadata.gz: 6904923fe040ae2f15775a19e12d70d63e2a55f95d5fa81eaaa8722653a5d8022d58ea08794ecdbab6dace1cde8d4bb47165e2be46c3515c698fa686e60d10a9
7
+ data.tar.gz: 2df68f40d9a4e0cb9534e13a615cbd23267668a090edfd75cbed20e0f568882d7e67b5e0585d12dcac24e64d8915d412e8fa072e334ae0132161164ea39aaf87
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # motion-weakattr
2
+
3
+ A zeroing `attr_accessor` replacement using `WeakRef`:
4
+
5
+ ```ruby
6
+ class MyClass
7
+ weak_attr :delegate
8
+ end
9
+
10
+ @obj = MyClass.new
11
+ autorelease_pool {
12
+ @obj.delegate = MyDelegate.new # wraps `delegate` in a WeakRef
13
+ @obj.delegate
14
+ # => #<MyDelegate:0x123123>
15
+ }
16
+ @obj.delegate # after deallocation
17
+ # => nil
18
+ ```
19
+
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ gem 'motion-weakattr'
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install motion-weakattr
34
+
35
+
36
+ ## Contact
37
+
38
+ [Clay Allsopp](http://twitter.com/clayallsopp)
39
+ [clay@usepropeller.com](mailto:clay@usepropeller.com)
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
+ Motion::Project::App.setup do |app|
9
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion/**/*.rb")))
10
+ end
@@ -0,0 +1,34 @@
1
+ class Module
2
+ def weak_attr(*attrs)
3
+ attrs.each do |attr_name|
4
+ attr_accessor attr_name
5
+
6
+ normal_getter = "#{attr_name}"
7
+ normal_setter = "#{attr_name}="
8
+ with_getter = "#{attr_name}_with_weakref"
9
+ without_getter = "#{attr_name}_without_weakref"
10
+ with_setter = "#{attr_name}_with_weakref="
11
+ without_setter = "#{attr_name}_without_weakref="
12
+
13
+ define_method(with_setter) do |value|
14
+ self.send(without_setter, WeakRef.new(value))
15
+ end
16
+
17
+ define_method(with_getter) do
18
+ value = self.send(without_getter)
19
+ if value.respond_to?(:weakref_alive?)
20
+ return value if value.weakref_alive?
21
+ nil
22
+ else
23
+ value
24
+ end
25
+ end
26
+
27
+ alias_method without_getter, normal_getter
28
+ alias_method normal_getter, with_getter
29
+
30
+ alias_method without_setter, normal_setter
31
+ alias_method normal_setter, with_setter
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-weakattr
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Clay Allsopp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: weak_attr for WeakRefs in RubyMotion
28
+ email:
29
+ - clay@usepropeller.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/motion/motion-weakattr.rb
36
+ - lib/motion-weakattr.rb
37
+ homepage: http://github.com/usepropeller/motion-weakattr
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: weak_attr for WeakRefs in RubyMotion
61
+ test_files: []