Class: Pmux::Cleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/pmux/cleaner.rb

Instance Method Summary collapse

Constructor Details

#initialize(*glob_pats) ⇒ Cleaner

Returns a new instance of Cleaner.



5
6
7
# File 'lib/pmux/cleaner.rb', line 5

def initialize *glob_pats
  @glob_pats = glob_pats
end

Instance Method Details

#clean(glob_pat = nil, lim_time = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pmux/cleaner.rb', line 14

def clean glob_pat=nil, lim_time=nil
  glob_pat ||= ''
  lim_time ||= Time.now - 3600*24*7
  paths = Dir.glob glob_pat
  for path in paths
    if File.exist? path
      mtime = File.mtime path
      if mtime < lim_time
        FileUtils.rm_rf path
      end
    end
  end
end

#run(lim_time = nil) ⇒ Object



9
10
11
12
# File 'lib/pmux/cleaner.rb', line 9

def run lim_time=nil
  fork {fork {@glob_pats.each {|glob_pat| clean glob_pat, lim_time}}}
  Process.wait
end