Class: ProScribe::Watcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, &blk) ⇒ Watcher

Returns a new instance of Watcher.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/proscribe/watcher.rb', line 11

def initialize(project, &blk)
  require 'fssm'

  @threads = Array.new

  # Monitor the project's manual
  @threads << Thread.new {
    monitor(project.config.manual) { |*a| project.make; yield *a }
  }

  # Monitor ProScribe's default theme
  @threads << Thread.new {
    monitor(ProScribe.root('data')) { |*a| project.make; yield *a }
  }

  # Monitor the project's files
  project.config.files.each do |group|
    threads << Thread.new {
      path = project.root(group.source)
      path = path.gsub(/\*.*$/, '')
      path = File.realpath(path)

      monitor(path) { |*a| project.make; yield *a }
    }
  end
end

Instance Attribute Details

#threadsObject (readonly)

Attribute: threads (ProScribe::Watcher) The threads.



41
42
43
# File 'lib/proscribe/watcher.rb', line 41

def threads
  @threads
end

Instance Method Details

#joinObject

Method: join (ProScribe::Watcher) Asks all threads to join.



46
47
48
# File 'lib/proscribe/watcher.rb', line 46

def join
  threads.each { |t| t.join }
end