Class: Makit::Docs::Rake
- Inherits:
-
Object
- Object
- Makit::Docs::Rake
- Defined in:
- lib/makit/docs/rake.rb
Overview
This class provide methods for generating documentation about source files and artifacts.
docs/Files.md
Class Method Summary collapse
- .duration ⇒ Object
- .generate ⇒ Object
- .get_top_level_tasks ⇒ Object
- .get_top_task_name ⇒ Object
-
.properties ⇒ Object
return a hash of name => value for properties of the rake execution.
- .start_time ⇒ Object
Class Method Details
.duration ⇒ Object
24 25 26 |
# File 'lib/makit/docs/rake.rb', line 24 def self.duration Time.now - Makit::STARTTIME end |
.generate ⇒ Object
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 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/makit/docs/rake.rb', line 56 def self.generate # if the top level tasks are of size 1, with the name "default", # then we will continue to generate the documentation. # otherwise, we will display a message and exit. if get_top_level_tasks.size != 1 || get_top_level_tasks.first != "default" puts " no top level tasks specified, skipping rake documentation generation".colorize(:yellow) return end content = "" # display: "Rake default completed in HUMANIZED_DURATION" content += "# Rake default\n\n" # display a table of the properties content += "## Properties\n\n" properties.each do |key, value| content += "| #{key} | #{value} |\n" end content += "\n\n" # display the completed tasks content += "## Completed Tasks\n\n" Makit::TaskInfo.completed_tasks.each do |task_name, task_info| content += "| #{task_name} | #{Makit::Humanize.get_humanized_duration(task_info[:duration])} |\n" end content += "\n\n" ## report on the available rake tasks content += Makit::Commands::Runner.default.execute("rake -T").to_markdown content += "\n\n" filename = "docs/Rake.md" FileUtils.mkdir_p("docs") # overwrite the file if it exists if File.exist?(filename) existing_content = File.read(filename) if existing_content != content File.delete(filename) File.write(filename, content) end else File.write(filename, content) end end |
.get_top_level_tasks ⇒ Object
16 17 18 |
# File 'lib/makit/docs/rake.rb', line 16 def self.get_top_level_tasks ::Rake.application.top_level_tasks end |
.get_top_task_name ⇒ Object
20 21 22 |
# File 'lib/makit/docs/rake.rb', line 20 def self.get_top_task_name get_top_level_tasks.first end |
.properties ⇒ Object
return a hash of name => value for properties of the rake execution
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/makit/docs/rake.rb', line 33 def self.properties { "top_level_tasks" => get_top_level_tasks, # If global VERSION is defined, then add it to the properties (this is NOT the Makit::VERSION) "version" => (defined?(VERSION) ? VERSION : ""), "branch" => Makit::Git::Repository.branch, # add the current user name "user" => ENV.fetch("USER", nil), # add the current machine name "machine" => ENV.fetch("COMPUTERNAME", nil), # add the os name "os" => ENV.fetch("OS", nil), "duration" => Makit::Humanize.get_humanized_duration(duration), "start_time" => Makit::Humanize.(start_time), "source_file_count" => Makit::Git::Repository.get_file_infos.count, "source_file_size" => Makit::Humanize.get_humanized_size(Makit::Git::Repository.get_file_infos.sum(&:size)), "untracked_file_count" => Makit::Git::Repository.get_untracked_file_infos.count, "untracked_file_size" => Makit::Humanize.get_humanized_size(Makit::Git::Repository.get_untracked_file_infos.sum(&:size)), # express the ratio of untracked file size to tracked file size as a percentage "ratio_untracked_size_to_tracked_size" => ((Makit::Git::Repository.get_untracked_file_infos.sum(&:size) / Makit::Git::Repository.get_file_infos.sum(&:size)) * 100).to_i, } end |
.start_time ⇒ Object
28 29 30 |
# File 'lib/makit/docs/rake.rb', line 28 def self.start_time Makit::STARTTIME end |