module FileChangeReporting

Public Instance Methods

become_reporter_daemon(directory) click to toggle source
# File lib/repo_timetracker/file_change_reporting.rb, line 11
def become_reporter_daemon(directory)
  if defined? Process.daemon
    Process.daemon
    
    FileWatcher.new([@repo_directory]).watch do |filename|
      RepoTimeline.add_event "File changed: #{filename.slice(/[^\/]+$/)}"
    end
  end
end
kill_reporter_daemons() click to toggle source
# File lib/repo_timetracker/file_change_reporting.rb, line 5
def kill_reporter_daemons
  timetracker_process_pids.each do |pid|
    Process.kill("HUP", pid) if is_not_current_process(pid)
  end
end

Private Instance Methods

is_not_current_process(pid) click to toggle source
# File lib/repo_timetracker/file_change_reporting.rb, line 24
def is_not_current_process(pid)
  pid != Process.pid
end
pid_from_string(process_string) click to toggle source
# File lib/repo_timetracker/file_change_reporting.rb, line 35
def pid_from_string(process_string)
  pid_string = process_string.match(/\d+/)[0]
  Integer(pid_string)
end
timetracker_process_pids() click to toggle source
# File lib/repo_timetracker/file_change_reporting.rb, line 28
def timetracker_process_pids
  processes = `ps -ax | grep 'ruby.*rpt rec'`.split("\n")
  processes_without_that_grep = processes.select { |p| not p.include? 'grep' }

  processes_without_that_grep.map { |p| pid_from_string(p) }
end