Class: MotionWiretap::WiretapKvo
- Inherits:
-
WiretapTarget
- Object
- Wiretap
- WiretapTarget
- MotionWiretap::WiretapKvo
- Defined in:
- lib/motion-wiretap/all/wiretap.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from WiretapTarget
Instance Method Summary collapse
- #bind_to(wiretap) ⇒ Object
-
#initialize(target, property, &block) ⇒ WiretapKvo
constructor
A new instance of WiretapKvo.
- #observeValueForKeyPath(path, ofObject: target, change: change, context: context) ⇒ Object
- #teardown ⇒ Object
- #trigger_changed(*values) ⇒ Object
Methods inherited from Wiretap
#and_then, #cancel!, #combine, #dealloc, #enqueue, #filter, #listen, #map, #on_error, #queue, #reduce, #trigger_changed_on, #trigger_completed, #trigger_completed_on, #trigger_error, #trigger_error_on
Constructor Details
#initialize(target, property, &block) ⇒ WiretapKvo
Returns a new instance of WiretapKvo.
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 206 def initialize(target, property, &block) @property = property @value = nil @initial_is_set = false @bound_to = [] super(target, &block) @target.addObserver(self, forKeyPath: property.to_s, options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial, context: nil ) end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
203 204 205 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 203 def property @property end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
204 205 206 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 204 def value @value end |
Instance Method Details
#bind_to(wiretap) ⇒ Object
232 233 234 235 236 237 238 239 240 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 232 def bind_to(wiretap) @bound_to << wiretap wiretap.listen do |value| @target.send("#{@property}=".to_sym, value) end wiretap.trigger_changed return self end |
#observeValueForKeyPath(path, ofObject: target, change: change, context: context) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 242 def observeValueForKeyPath(path, ofObject: target, change: change, context: context) @value = change[NSKeyValueChangeNewKey] if @initial_is_set trigger_changed(@value) else @initial_is_set = true end end |
#teardown ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 220 def teardown @target.removeObserver(self, forKeyPath: @property.to_s ) @bound_to.each &:cancel! super end |
#trigger_changed(*values) ⇒ Object
228 229 230 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 228 def trigger_changed(*values) super(@value) end |