Class: Weigh::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/weigh/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flags) ⇒ Runner

Returns a new instance of Runner.



10
11
12
# File 'lib/weigh/runner.rb', line 10

def initialize(flags)
  @flags = flags
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



8
9
10
# File 'lib/weigh/runner.rb', line 8

def flags
  @flags
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/weigh/runner.rb', line 14

def run
  total_size = 0
  summary = {}
  count = 0
  sumdep = @flags.depth

  @flags.pathlist.each do |p|
    curdep = 0
    Find.find(p) do |path|
      count += 1
      next if FileTest.symlink?(path)
      if FileTest.directory?(path)
        next if p == path
        ret = Weigh::Util.sum_dir(path,@flags.verbose)
        dir_size = ret[:dir_size]
        next if dir_size == 0
        count += ret[:count]
        total_size += dir_size
        summary["#{path}/"] = dir_size
        Find.prune
      else
        size = FileTest.size(path)
        next if size == 0
        total_size += size
        summary["#{path}"] = size
      end
    end
  end

  Weigh::Util.report(summary,total_size)
end