Class: Slick::ProjectWatcher

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/slick/project_watcher.rb

Constant Summary

Constants included from Helpers

Helpers::SELF_CLOSING_TAGS, Helpers::TAGS, Helpers::TEXT_ONLY_TAGS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#html_tag, #indent, #line, #text

Class Method Details

.watchObject



6
7
8
# File 'lib/slick/project_watcher.rb', line 6

def self.watch
    self.new.watch
end

Instance Method Details

#watchObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/slick/project_watcher.rb', line 12

def watch
    last_modified_times = {}

    while true
        is_change = false

        Dir.glob("#{project.root_path}/**/*").each do |file|
            last_modified_time = File.mtime(file)
            if last_modified_times[file] != last_modified_time
                is_change = true
            end
            last_modified_times[file] = last_modified_time
        end

        if is_change
            Process.kill('KILL', @child_process_pid) if @child_process_pid
            @child_process_pid = Process.fork
            break if !@child_process_pid
            
        end
    end
end