Module: Makit::Directories
- Defined in:
- lib/makit/directories.rb
Overview
This class provide methods for working with the system Environment.
Constant Summary collapse
- ROOT =
File.join(Dir.home, ".makit")
- CLONE =
File.join(Dir.home, ".makit", "clone")
- MAKE =
File.join(Dir.home, ".makit", "make")
- LOG =
File.join(Dir.home, ".makit", "log")
- WORK =
File.join(Dir.home, ".makit", "work")
- REPOS =
File.join(Dir.home, ".makit", "repos")
- TEMP =
File.join(Dir.home, ".makit", "temp")
- INSTALL =
File.join(Dir.home, ".makit", "install")
- NUGET =
File.join(Dir.home, ".makit", "nuget")
- HOME =
Makit::Directory.normalize(Dir.home)
- ONEDRIVE =
File.join(Dir.home, "OneDrive")
- ONEDRIVE_NUGET_SOURCE =
File.join(ONEDRIVE, "code", "artifacts", "nuget")
- ONEDRIVE_CONSOLE_SOURCE =
File.join(ONEDRIVE, "code", "artifacts", "console")
- ONEDRIVE_INSTALLER_SOURCE =
File.join(ONEDRIVE, "code", "artifacts", "installer")
- CURRENT =
Dir.pwd
- LOCAL_APPLICATION_DATA =
File.join(HOME, "AppData", "Local")
- RAKEDIR =
Rake.application.init Rake.application.load_rakefile
Dir.pwd
- PROJECT_ROOT =
File.dirname(Rake.application.rakefile)
Makit::Directory.find_directory_with_patterns(RAKEDIR, ["Rakefile", "rakefile.rb", ".gitignore"])
- PROJECT_ARTIFACTS =
PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “Rakefile”) PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “rakefile.rb”) PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “.gitignore”)
if PROJECT_ROOT.nil? nil else File.join(PROJECT_ROOT, "artifacts") end
- LOCAL_NUGET_SOURCE =
File.join(Dir.home, ".makit", "nuget")
- NUGET_PACKAGE_CACHE =
NUGET_PACKAGE_CACHE = “#"USERPROFILE"\.nuget\packages”
Makit::Directory.normalize("#{Dir.home}/.nuget/packages")
- SERVICES =
if Makit::Environment.get_os == "macOS" "/Library/LaunchDaemons" else "/etc/systemd/system" end
- GRPC_TOOLS_PATH =
File.join(NUGET_PACKAGE_CACHE, "grpc.tools", Makit::Protoc.get_latest_grpc_tools_version)
- GRPC_CSHARP_PLUGIN_PATH =
Makit::Protoc.find_plugin_path("grpc_csharp_plugin")
Class Method Summary collapse
- .get_clone_directory(url) ⇒ Object
- .get_log_directory(url) ⇒ Object
- .get_make_commit_directory(url, commit_id) ⇒ Object
- .get_make_commit_log_filename(url, commit_id) ⇒ Object
- .get_make_directory(url) ⇒ Object
-
.get_project_path(relative_path) ⇒ Object
NOTE: Nuget source setup moved to lazy initialization to avoid blocking module loading.
- .get_relative_directory(url) ⇒ Object
- .get_work_directory(url) ⇒ Object
-
.show ⇒ Object
show all the directory constants in a nicely formatted table format with the name of the constant and the value.
Class Method Details
.get_clone_directory(url) ⇒ Object
80 81 82 |
# File 'lib/makit/directories.rb', line 80 def self.get_clone_directory(url) File.join(CLONE, get_relative_directory(url)) end |
.get_log_directory(url) ⇒ Object
96 97 98 |
# File 'lib/makit/directories.rb', line 96 def self.get_log_directory(url) File.join(LOG, get_relative_directory(url)) end |
.get_make_commit_directory(url, commit_id) ⇒ Object
92 93 94 |
# File 'lib/makit/directories.rb', line 92 def self.get_make_commit_directory(url, commit_id) File.join(MAKE, get_relative_directory(url), commit_id) end |
.get_make_commit_log_filename(url, commit_id) ⇒ Object
100 101 102 |
# File 'lib/makit/directories.rb', line 100 def self.get_make_commit_log_filename(url, commit_id) File.join(LOG, get_relative_directory(url), "#{commit_id}.json") end |
.get_make_directory(url) ⇒ Object
88 89 90 |
# File 'lib/makit/directories.rb', line 88 def self.get_make_directory(url) File.join(MAKE, get_relative_directory(url)) end |
.get_project_path(relative_path) ⇒ Object
NOTE: Nuget source setup moved to lazy initialization to avoid blocking module loading
76 77 78 |
# File 'lib/makit/directories.rb', line 76 def self.get_project_path(relative_path) File.join(PROJECT_ROOT, relative_path) end |
.get_relative_directory(url) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/makit/directories.rb', line 104 def self.get_relative_directory(url) # if url start with Directories::REPOS, then it is a local repository return url.gsub(REPOS, "") if url.start_with?(REPOS) url = url.gsub("https://", "").gsub("http://", "") url = url.gsub("gitlab.com", "gitlab") url = url.gsub("github.com", "github") # if the url ends with .git, remove it url = url.gsub(".git", "") if url.end_with?(".git") url end |
.get_work_directory(url) ⇒ Object
84 85 86 |
# File 'lib/makit/directories.rb', line 84 def self.get_work_directory(url) File.join(WORK, get_relative_directory(url)) end |
.show ⇒ Object
show all the directory constants in a nicely formatted table format with the name of the constant and the value
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/makit/directories.rb', line 118 def self.show # Array of constant names (symbols) constant_names = %i[ROOT CLONE MAKE LOG WORK REPOS TEMP INSTALL HOME ONEDRIVE CURRENT RAKEDIR PROJECT_ROOT PROJECT_ARTIFACTS LOCAL_NUGET_SOURCE NUGET_PACKAGE_CACHE SERVICES GRPC_TOOLS_PATH GRPC_CSHARP_PLUGIN_PATH] # Find the length of the longest constant name and add 1 max_length = constant_names.map(&:to_s).max_by(&:length).length + 1 # Iterate through each constant name constant_names.each do |constant_name| constant_value = const_get(constant_name) # Fetch the value of the constant constant_value = constant_value.colorize(:green) if !constant_value.nil? && Dir.exist?(constant_value) # Print the constant name right justified to the max_length puts "#{constant_name.to_s.rjust(max_length)} = #{constant_value}" rescue NameError # Handle the case where the constant is not defined puts "#{constant_name.to_s.rjust(max_length)} = [Constant not defined]" end end |