Class: Weigh::Run

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathlist = ['.']) ⇒ Run

Returns a new instance of Run.



9
10
11
12
13
14
15
16
17
# File 'lib/weigh/run.rb', line 9

def initialize(pathlist=['.'])
  @pathlist = pathlist

  @data              = {
    :total_size => 0,
    :summary    => {},
    :count      => 0
  }
end

Instance Attribute Details

#pathlistObject

Returns the value of attribute pathlist.



7
8
9
# File 'lib/weigh/run.rb', line 7

def pathlist
  @pathlist
end

#verboseObject

Returns the value of attribute verbose.



7
8
9
# File 'lib/weigh/run.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#reportObject



82
83
84
# File 'lib/weigh/run.rb', line 82

def report
  Weigh::Util.report @data
end

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/weigh/run.rb', line 35

def run
  # Dig into each path given
  @pathlist.each do |p|
    Find.find(p) do |path|
      @data[:count] += 1

      # Skip symlinks
      next if FileTest.symlink?(path)

      if FileTest.directory?(path)

        # Skip the path that we are already on
        next if p == path

        # Summarize the directory data
        ret = Weigh::Util.sum_dir(path,@verbose)
        dir_size = ret[:dir_size]

        # Skip empty directories
        next if dir_size == 0

        # Record the data from the directory
        @data[:count]      += ret[:count]
        @data[:total_size] += dir_size

        # Add a trailing slash to the key for directories
        pathname = path + "/"

        @data[:summary][pathname] = dir_size

        Find.prune
      else
        # Store the size of the current file
        size = FileTest.size(path)

        # Don't count zero sized files
        next if size == 0

        @data[:total_size] += size
        @data[:summary][path] = size
      end
    end
  end

  @data
end