Module: DubbletrackRemote::Reader

Defined in:
lib/dubbletrack_remote/reader/dbf.rb,
lib/dubbletrack_remote/reader/tsv.rb,
lib/dubbletrack_remote/reader/base.rb

Defined Under Namespace

Classes: Base, DBF, TSV

Class Method Summary collapse

Class Method Details

.new(file_path, options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/dubbletrack_remote/reader/base.rb', line 4

def self.new(file_path, options = {})
  if File.extname(file_path) == ".DBF"
    DubbletrackRemote::Reader::DBF.new(file_path, options)
  elsif File.extname(file_path) == ".TSV"
    DubbletrackRemote::Reader::TSV.new(file_path, options)
  end
end

.watch(playlist_path, options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dubbletrack_remote/reader/base.rb', line 12

def self.watch(playlist_path, options = {}, &block)
  pattern = options[:pattern] || Regexp.new(".+")
  listener = Listen.to(playlist_path, force_polling: true, wait_for_delay: 4) do |modified, added|
    [modified, added].flatten.compact.uniq.each do |file|
      if pattern.match(file)
        block.call(file)
      end
    end
  rescue => e
    puts "errored while listening for changes, will continue listening"
    puts e
  end

  listener.start
end