class Spectator::PathWatcher

Attributes

config[R]
queue[R]

Public Class Methods

new(config) click to toggle source
# File lib/spectator/path_watcher.rb, line 8
def initialize(config)
  @config = config
  @queue = Queue.new
end

Public Instance Methods

has_changed_files?() click to toggle source
# File lib/spectator/path_watcher.rb, line 13
def has_changed_files?
  queue.size > 0
end
listener() click to toggle source
# File lib/spectator/path_watcher.rb, line 35
def listener
  @listener ||= begin
    listener = Listen.to(Dir.pwd, :relative_paths => true)
    p [:watching, config.base_dir_regexp]
    listener = listener.filter %r{^(#{config.base_dir_regexp}|#{config.spec_dir_regexp})/}
    listener = listener.change do  |modified, added, removed|
      p ['modified, added, removed', modified, added, removed]

      if added.any? or removed.any?
        Spectator::SpecsMatcher.reset_matchable_spec_files!
      end

      files = [modified, added].flatten
      files.each { |relative| queue.push relative }
      p on_change
      on_change.call(files) if on_change && files.any?
    end
  end
end
on_change(&block) click to toggle source
# File lib/spectator/path_watcher.rb, line 17
def on_change &block
  @on_change = block if block_given?
  @on_change
end
pop_files() click to toggle source
# File lib/spectator/path_watcher.rb, line 22
def pop_files
  files = []
  queue.size.times { files << queue.pop }
  files
end
watch_paths!() click to toggle source
# File lib/spectator/path_watcher.rb, line 28
def watch_paths!
  listener.start
end