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.
Attributes inherited from WiretapTarget
Attributes inherited from Wiretap
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
Methods inherited from Wiretap
#and_then, #cancel!, #combine, #dealloc, #enqueue, #filter, #listen, #map, #on_error, #queue, #reduce, #trigger_changed, #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.
227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 227 def initialize(target, property, &block) @property = property @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.
225 226 227 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 225 def property @property end |
Instance Method Details
#bind_to(wiretap) ⇒ Object
248 249 250 251 252 253 254 255 256 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 248 def bind_to(wiretap) @bound_to << wiretap wiretap.listen do |value| @target.send("#{@property}=".to_sym, value) end wiretap.trigger_changed(wiretap.value) return self end |
#observeValueForKeyPath(path, ofObject: target, change: change, context: context) ⇒ Object
258 259 260 261 262 263 264 265 266 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 258 def observeValueForKeyPath(path, ofObject: target, change: change, context: context) value = change[NSKeyValueChangeNewKey] if @initial_is_set trigger_changed(value) else @value = value @initial_is_set = true end end |
#teardown ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/motion-wiretap/all/wiretap.rb', line 240 def teardown @target.removeObserver(self, forKeyPath: @property.to_s ) @bound_to.each &:cancel! super end |