Sha256: 059f06052b38ccb93f85e664d4ed4e181348799bd88ede116d38acf071d6dd52

Contents?: true

Size: 982 Bytes

Versions: 5

Compression:

Stored size: 982 Bytes

Contents

require 'listen'

class Maid::Watch
  include Maid::RuleContainer

  attr_reader :path, :listener, :logger

  def initialize(maid, path, options = {}, &rules)
    @maid = maid

    if options.nil? || options.empty?
      @lazy = true
      @options = { wait_for_delay: 10,
                   ignore: Maid::Downloading.downloading_file_regexps }
    else
      @lazy = options.delete(:lazy) { |key| true }
      @options = options
    end

    @logger = maid.logger # TODO: Maybe it's better to create seperate loggers?
    @path = File.expand_path(path)
    initialize_rules(&rules)
  end

  def run
    unless rules.empty?
      @listener = Listen.to(path, @options) do |modified, added, removed|
        if !@lazy || added.any? || removed.any?
          follow_rules(modified, added, removed)
        end
      end

      @listener.start
    end
  end

  def stop
    @listener.stop
  end

  def join
    @listener.thread.join unless @listener.nil? || @listener.paused?
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maid-0.10.0.pre.alpha.1 lib/maid/watch.rb
maid-0.9.0.alpha.2 lib/maid/watch.rb
maid-0.9.0.alpha.1 lib/maid/watch.rb
maid-0.8.0.alpha.4 lib/maid/watch.rb
maid-0.8.0.alpha.3 lib/maid/watch.rb