Class: Kernel
- Inherits:
-
Object
- Object
- Kernel
- Defined in:
- motion-prime/core_ext/kernel.rb
Instance Method Summary collapse
- #allocate_strong_references(key = nil) ⇒ Object
- #allocated_references_released? ⇒ Boolean
- #class_name_without_kvo ⇒ Object
- #clear_instance_variables(options = {}) ⇒ Object
- #pp(*attrs) ⇒ Object
- #release_strong_references(key = nil) ⇒ Object
- #strong_ref ⇒ Object
- #weak_ref ⇒ Object
Instance Method Details
#allocate_strong_references(key = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'motion-prime/core_ext/kernel.rb', line 19 def allocate_strong_references(key = nil) unless self.respond_to?(:strong_references) Prime.logger.debug "User must define `strong_references` in `#{self.class.name}`" return false end refs = Array.wrap(self.strong_references).compact unless refs.present? Prime.logger.debug "`strong_references` are empty for `#{self.class.name}`" return false end @_strong_references ||= {} key ||= [@_strong_references.count, Time.now.to_i].join('_') @_strong_references[key] = refs.map(&:strong_ref) key end |
#allocated_references_released? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'motion-prime/core_ext/kernel.rb', line 47 def allocated_references_released? unless self.respond_to?(:strong_references) Prime.logger.debug "User must define `strong_references` in `#{self.class.name}`" return false end @_strong_references.all? { |key, ref| @_strong_references.count; ref.retainCount == @_strong_references.count } end |
#class_name_without_kvo ⇒ Object
7 8 9 |
# File 'motion-prime/core_ext/kernel.rb', line 7 def class_name_without_kvo self.class.name.gsub(/^NSKVONotifying_/, '') end |
#clear_instance_variables(options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'motion-prime/core_ext/kernel.rb', line 55 def clear_instance_variables( = {}) ivars = self.instance_variables excluded_ivars = Array.wrap([:except]).map(&:to_s) clear_block = proc { |ivar| next if excluded_ivars.include?(ivar[1..-1]) self.instance_variable_set(ivar, nil) }.weak! ivars.each(&clear_block) end |
#pp(*attrs) ⇒ Object
2 3 4 5 |
# File 'motion-prime/core_ext/kernel.rb', line 2 def pp(*attrs) NSLog([*attrs].map(&:inspect).join(' ')) attrs end |
#release_strong_references(key = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'motion-prime/core_ext/kernel.rb', line 37 def release_strong_references(key = nil) unless self.respond_to?(:strong_references) Prime.logger.debug "User must define `strong_references` in `#{self.class.name}`" return false end key ||= @_strong_references.keys.last @_strong_references.try(:delete, key) key end |
#strong_ref ⇒ Object
15 16 17 |
# File 'motion-prime/core_ext/kernel.rb', line 15 def strong_ref self end |
#weak_ref ⇒ Object
11 12 13 |
# File 'motion-prime/core_ext/kernel.rb', line 11 def weak_ref WeakRef.new(self) end |