Class: RoCommands::Info

Inherits:
Base
  • Object
show all
Includes:
DSL::File
Defined in:
lib/ro_commands/info.rb

Defined Under Namespace

Classes: RoFile

Instance Method Summary collapse

Methods included from DSL::File

#dir?, #file?, #find, #size

Methods inherited from Base

describe, method_added, meths, usage

Methods included from Bash

#_bash, #bash, #bash_lines, #bash_per, #handle_path

Instance Method Details

#file_size(path, recursive = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ro_commands/info.rb', line 27

def file_size(path, recursive=false)
  if recursive
    find(path).each do |f|
      files << RoFile.new(f, size(f))
    end
    puts files.sort_by(&:size)
  else
    Dir[File.join(path, "**")].each do |f|
      if dir?(f)
        s = find(f).inject(0) { |total_size, file_size| total_size += size(f) }
        rf = RoFile.new(f, s)
      else
        rf = RoFile.new(f, size(f))
      end
      files << rf
    end

    puts files.sort_by(&:size)
  end
end