Class: Makit::Docs::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/docs/files.rb

Overview

This class provide methods for generating documentation about source files and artifacts.

docs/Files.md

Class Method Summary collapse

Class Method Details

.generateObject



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
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
81
82
83
84
85
86
# File 'lib/makit/docs/files.rb', line 16

def self.generate
  filename = "docs/Files.md"
  FileUtils.mkdir_p("docs")
  # overwrite the file if it exists
  FileUtils.rm_f(filename)
  File.open(filename, "w") do |file|
    file.write("# Files\n\n")
    file.write("A file summary for the project #{Makit::Git::Repository.get_remote_url}.\n\n")

    #
    # Tracked Files
    #
    # report on the file tracked by git.
    tracked_file_infos = Makit::Git::Repository.get_file_infos

    # first display the count and total size of the files tracked by git.
    file.write("## Tracked Files\n\n")
    file.write("#{tracked_file_infos.count} files with a total size of #{Makit::Humanize.get_humanized_size(tracked_file_infos.sum(&:size))}.\n\n")

    # next display a table of the 10 tracked files that have been modified recently.
    # ordered by last modified date, display the size, name, and last modified date.
    # leverage the humanize class to display the size in a human readable format.
    # leverage the humanize class to display the last modified date in a human readable format.
    file.write("The 10 files tracked by git that have been modified recently are:\n\n")
    file.write("| Size | Name | Last Modified Date |\n")
    file.write("|------|------|------------------|\n")
    tracked_file_infos.sort_by(&:mtime).reverse.first(10).each do |file_info|
      file.write("| #{Makit::Humanize.get_humanized_size(file_info.size)} | #{file_info.name} | #{Makit::Humanize.get_humanized_timestamp(file_info.mtime)} |\n")
    end
    file.write("\n")

    # next display a table or the largest 10 files tracked by git.
    # ordered by latest size first, display the size, name, and last modified date.
    # leverage the humanize class to display the size in a human readable format.
    # leverage the humanize class to display the last modified date in a human readable format.
    file.write("The 10 largest files tracked by git are:\n\n")
    file.write("| Size | Name | Last Modified Date |\n")
    file.write("|------|------|------------------|\n")
    tracked_file_infos.sort_by(&:size).reverse.first(10).each do |file_info|
      file.write("| #{Makit::Humanize.get_humanized_size(file_info.size)} | #{file_info.name} | #{Makit::Humanize.get_humanized_timestamp(file_info.mtime)} |\n")
    end
    file.write("\n")

    #
    # Untracked Files
    #
    # report on the files that are not tracked by git.
    untracked_file_infos = Makit::Git::Repository.get_untracked_file_infos
    # display the count and total size of the files that are not tracked by git.
    file.write("## Untracked Files\n\n")
    file.write("#{untracked_file_infos.count} files with a total size of #{Makit::Humanize.get_humanized_size(untracked_file_infos.sum(&:size))}.\n\n")
    # next display a table or the largest 10 files not tracked by git.
    # ordered by latest size first, display the size, name, and last modified date.
    # leverage the humanize class to display the size in a human readable format.
    # leverage the humanize class to display the last modified date in a human readable format.
    file.write("The 10 largest files not tracked by git are:\n\n")
    file.write("| Size | Name | Last Modified Date |\n")
    file.write("|------|------|------------------|\n")
    untracked_file_infos.sort_by(&:size).reverse.first(10).each do |file_info|
      file.write("| #{Makit::Humanize.get_humanized_size(file_info.size)} | #{file_info.name} | #{Makit::Humanize.get_humanized_timestamp(file_info.mtime)} |\n")
    end
    file.write("\n")

    #
    # Git Repository Size
    #
    ## report on the git repository size
    file.write(Makit::Commands::Runner.default.execute("git count-objects -vH").to_markdown)
    file.write("\n\n")
  end
end