module Filewatcher::Cycles

Module for all cycles in ‘Filewatcher#watch`

Private Instance Methods

before_pausing_sleep() click to toggle source
Calls superclass method
# File lib/filewatcher/cycles.rb, line 30
def before_pausing_sleep
  super if defined?(super)
end
before_watching_sleep() click to toggle source
Calls superclass method
# File lib/filewatcher/cycles.rb, line 45
def before_watching_sleep
  super if defined?(super)
end
main_cycle() click to toggle source
# File lib/filewatcher/cycles.rb, line 8
def main_cycle
  while @keep_watching
    @end_snapshot = current_snapshot if @pausing

    pausing_cycle

    watching_cycle

    # test and clear @changes to prevent yielding the last
    # changes twice if @keep_watching has just been set to false
    trigger_changes
  end
end
pausing_cycle() click to toggle source
# File lib/filewatcher/cycles.rb, line 22
def pausing_cycle
  while @keep_watching && @pausing
    before_pausing_sleep

    sleep @interval
  end
end
trigger_changes(on_update = @on_update) click to toggle source
# File lib/filewatcher/cycles.rb, line 49
def trigger_changes(on_update = @on_update)
  debug __method__
  on_update.call(@changes.dup) unless @changes.empty?
  @changes.clear
  debug '@changes cleared'
end
watching_cycle() click to toggle source
# File lib/filewatcher/cycles.rb, line 34
def watching_cycle
  @last_snapshot ||= current_snapshot
  loop do
    before_watching_sleep

    debug "#{__method__} sleep #{@interval}"
    sleep @interval
    break if !@keep_watching || file_system_updated? || @pausing
  end
end