Class: Specwrk::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/specwrk/watcher.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, queue, watchfile = "Specwrk.watchfile.rb") ⇒ Watcher

Returns a new instance of Watcher.



54
55
56
57
58
# File 'lib/specwrk/watcher.rb', line 54

def initialize(dir, queue, watchfile = "Specwrk.watchfile.rb")
  @dir = dir
  @queue = queue
  @config = Config.load(watchfile)
end

Class Method Details

.watch(dir, queue, watchfile) ⇒ Object



48
49
50
51
52
# File 'lib/specwrk/watcher.rb', line 48

def self.watch(dir, queue, watchfile)
  instance = new(dir, queue, watchfile)

  instance.start
end

Instance Method Details

#push(paths) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/specwrk/watcher.rb', line 64

def push(paths)
  paths.each do |path|
    relative_path = Pathname.new(path).relative_path_from(Pathname.new(dir)).to_s

    spec_files = config.spec_files_for(relative_path)

    spec_files.each do |spec_file_path|
      queue.push(spec_file_path) if File.exist?(spec_file_path)
    end
  end
end

#startObject



60
61
62
# File 'lib/specwrk/watcher.rb', line 60

def start
  listener.start
end