lib/makit/environment.rb in makit-0.0.53 vs lib/makit/environment.rb in makit-0.0.54

- old
+ new

@@ -1,127 +1,127 @@ -# frozen_string_literal: true - -require "sorted_set" -require_relative "directory" -# This module provides classes for the Makit gem. -module Makit - # This class provide methods for working with the system Environment. - # - class Environment - def self.which(name) - return name if File.exist?(name) - - ["", ".exe", ".bat", ".cmd"].each do |ext| - aname = name + ext - return aname if File.exist?(aname) - - ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| - apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/") - return apath if File.exist?(apath) - end - end - "" - end - - def self.constants_hash - constants = {} - # collect all constants that are all uppercase - Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } # puts "#{c} = #{Object.const_get(c)}" } - #Object.constants.each { |c| constants[c] = Object.const_get(c)}# puts "#{c} = #{Object.const_get(c)}" } - constants - end - - def self.rake_file_name - caller_locations.each do |location| - return location.absolute_path if location.absolute_path&.end_with?("Rakefile") - end - nil - end - - def self.gem_data_directory - gem_data_directory = File.join(Dir.home, ".makit") - end - - def self.project_root_directory - if !Makit::Environment.rake_file_name.nil? - File.dirname(Makit::Environment.rake_file_name) - else - Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile") - # lass Directory - # def self.find_directory_with_pattern(starting_directory, pattern) - # nil - end - end - - def self.get_relative_directory(url) - url = url.gsub("https://", "").gsub("http://", "") - url = url.gsub("gitlab.com", "gitlab") - url - end - - def self.get_code_root - # user home directory + "code" - code_root = File.join(Dir.home, "code") - end - - def self.get_work_directory(url) - raise "invalid url" if !url.include? "https://" - url = url.gsub("https://", "").gsub("http://", "") - #url = url.gsub("gitlab.com","gitlab") - url - end - - def self.is_windows? - RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - end - - def self.is_mac? - RbConfig::CONFIG["host_os"] =~ /darwin/ - end - - def self.get_os - case RbConfig::CONFIG["host_os"] - when /linux/ - "Linux" - when /darwin/ - "macOS" - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - "Windows" - else - "Unknown" - end - end - - def self.get_runtime_identifier() - os = RbConfig::CONFIG["host_os"] - cpu = RbConfig::CONFIG["host_cpu"] - - case os - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - os_rid = "win" - when /darwin|mac os/ - os_rid = "osx" - when /linux/ - os_rid = "linux" - when /solaris|bsd/ - os_rid = "unix" - else - raise "Unknown operating system: host_os=#{os}" - end - - case cpu - when /x86_64|amd64|x64/ - arch_rid = "x64" - when /i686|i386/ - arch_rid = "x86" - #when /arm/ - # arch_rid = "arm" - when /aarch64|arm64/ - arch_rid = "arm64" - else - raise "Unknown architecture: host_cpu=#{cpu}" - end - - "#{os_rid}-#{arch_rid}" - end - end -end +# frozen_string_literal: true + +require "sorted_set" +require_relative "directory" +# This module provides classes for the Makit gem. +module Makit + # This class provide methods for working with the system Environment. + # + class Environment + def self.which(name) + return name if File.exist?(name) + + ["", ".exe", ".bat", ".cmd"].each do |ext| + aname = name + ext + return aname if File.exist?(aname) + + ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| + apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/") + return apath if File.exist?(apath) + end + end + "" + end + + def self.constants_hash + constants = {} + # collect all constants that are all uppercase + Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } # puts "#{c} = #{Object.const_get(c)}" } + #Object.constants.each { |c| constants[c] = Object.const_get(c)}# puts "#{c} = #{Object.const_get(c)}" } + constants + end + + def self.rake_file_name + caller_locations.each do |location| + return location.absolute_path if location.absolute_path&.end_with?("Rakefile") + end + nil + end + + def self.gem_data_directory + gem_data_directory = File.join(Dir.home, ".makit") + end + + def self.project_root_directory + if !Makit::Environment.rake_file_name.nil? + File.dirname(Makit::Environment.rake_file_name) + else + Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile") + # lass Directory + # def self.find_directory_with_pattern(starting_directory, pattern) + # nil + end + end + + def self.get_relative_directory(url) + url = url.gsub("https://", "").gsub("http://", "") + url = url.gsub("gitlab.com", "gitlab") + url + end + + def self.get_code_root + # user home directory + "code" + code_root = File.join(Dir.home, "code") + end + + def self.get_work_directory(url) + raise "invalid url" if !url.include? "https://" + url = url.gsub("https://", "").gsub("http://", "") + #url = url.gsub("gitlab.com","gitlab") + url + end + + def self.is_windows? + RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + end + + def self.is_mac? + RbConfig::CONFIG["host_os"] =~ /darwin/ + end + + def self.get_os + case RbConfig::CONFIG["host_os"] + when /linux/ + "Linux" + when /darwin/ + "macOS" + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + "Windows" + else + "Unknown" + end + end + + def self.get_runtime_identifier() + os = RbConfig::CONFIG["host_os"] + cpu = RbConfig::CONFIG["host_cpu"] + + case os + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + os_rid = "win" + when /darwin|mac os/ + os_rid = "osx" + when /linux/ + os_rid = "linux" + when /solaris|bsd/ + os_rid = "unix" + else + raise "Unknown operating system: host_os=#{os}" + end + + case cpu + when /x86_64|amd64|x64/ + arch_rid = "x64" + when /i686|i386/ + arch_rid = "x86" + #when /arm/ + # arch_rid = "arm" + when /aarch64|arm64/ + arch_rid = "arm64" + else + raise "Unknown architecture: host_cpu=#{cpu}" + end + + "#{os_rid}-#{arch_rid}" + end + end +end