class MotionWiretap::WiretapKvo

Attributes

property[R]

Public Class Methods

new(target, property, &block) click to toggle source
Calls superclass method MotionWiretap::WiretapTarget::new
# 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

Public Instance Methods

bind_to(wiretap) click to toggle source
# File lib/motion-wiretap/all/wiretap.rb, line 248
def bind_to(wiretap)
  @bound_to << wiretap
  wiretap.listen do |*values|
    @target.send("#{@property}=".to_sym, wiretap.value)
  end
  wiretap.trigger_changed(wiretap.value)

  return self
end
observeValueForKeyPath(path, ofObject: target, change: change, context: context) click to toggle source
# 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() click to toggle source
Calls superclass method MotionWiretap::Wiretap#teardown
# File lib/motion-wiretap/all/wiretap.rb, line 240
def teardown
  @target.removeObserver(self,
    forKeyPath: @property.to_s
    )
  @bound_to.each &:cancel!
  super
end