class MotionWiretap::WiretapArray
Attributes
targets[R]
Public Class Methods
new(targets, &block)
click to toggle source
Calls superclass method
MotionWiretap::Wiretap::new
# File lib/motion-wiretap/all/wiretap.rb, line 273 def initialize(targets, &block) raise "Not only is listening to an empty array pointless, it will also cause errors" if targets.length == 0 # the complete trigger isn't called until all the wiretap are complete @uncompleted = targets.length # targets can be an array of Wiretap objects (they will be monitored), or # plain objects (they'll just be included in the sequence) super(&block) # gets assigned to the wiretap value if it's a Wiretap, or the object # itself if it is anything else. @values = [] @initial_is_set = true # maps the wiretap object (which is unique) @wiretaps = {} targets.each_with_index do |wiretap, index| unless wiretap.is_a? Wiretap @values << wiretap # not a wiretap, so doesn't need to be "completed" @uncompleted -= 1 else raise "You cannot store a Wiretap twice in the same sequence (for now - do you really need this?)" if @wiretaps.key?(wiretap) @wiretaps[wiretap] = index @values << wiretap.value wiretap.listen do |*values| indx = @wiretaps[wiretap] @values[indx] = wiretap.value trigger_changed(*@values) end wiretap.on_error do |error| trigger_error(error) end wiretap.and_then do |error| @uncompleted -= 1 if @uncompleted == 0 trigger_completed end end end end end
Public Instance Methods
teardown()
click to toggle source
Calls superclass method
MotionWiretap::Wiretap#teardown
# File lib/motion-wiretap/all/wiretap.rb, line 321 def teardown cancel = (->(wiretap){ wiretap.cancel! }).weak! @wiretaps.keys.each &cancel super end
trigger_changed(*values)
click to toggle source
Calls superclass method
MotionWiretap::Wiretap#trigger_changed
# File lib/motion-wiretap/all/wiretap.rb, line 327 def trigger_changed(*values) values = @values if values.length == 0 super(*values) end