Class: Raykit::Environment
- Inherits:
-
Object
- Object
- Raykit::Environment
- Defined in:
- lib/raykit/environment.rb
Overview
Provides functionality related to the development environment
Class Method Summary collapse
- .admin? ⇒ Boolean
-
.get_dev_dir(name) ⇒ Object
Get, and create if it does not exist, a specific development directory.
-
.get_dir_size(dir) ⇒ Object
Get the size of a directory and its contents.
- .get_work_dir(url) ⇒ Object
-
.home_dir ⇒ Object
The user home directory.
- .local_application_data ⇒ Object
- .log_dir ⇒ Object
- .machine ⇒ Object
-
.normalize_path(name) ⇒ Object
Normalize a directory or filename to use forward slashes.
-
.root_dir ⇒ Object
The root directory for the development environment.
- .user ⇒ Object
- .which(name) ⇒ Object
Class Method Details
.admin? ⇒ Boolean
69 70 71 72 |
# File 'lib/raykit/environment.rb', line 69 def self.admin? rights = `whoami /priv` rights.include?('SeCreateGlobalPrivilege') end |
.get_dev_dir(name) ⇒ Object
Get, and create if it does not exist, a specific development directory
36 37 38 39 40 |
# File 'lib/raykit/environment.rb', line 36 def self.get_dev_dir(name) dir = Pathname.new("#{Environment.root_dir}/#{name}") dir.mkpath dir.to_s.gsub('//', '/') end |
.get_dir_size(dir) ⇒ Object
Get the size of a directory and its contents
47 48 49 50 51 |
# File 'lib/raykit/environment.rb', line 47 def self.get_dir_size(dir) Dir.glob(File.join(dir, '**', '*')) .map { |f| File.size(f) } .inject(:+) end |
.get_work_dir(url) ⇒ Object
42 43 44 |
# File 'lib/raykit/environment.rb', line 42 def self.get_work_dir(url) "#{Raykit::Environment.get_dev_dir('work')}/#{url.gsub('://', '/').gsub('.git', '')}" end |
.home_dir ⇒ Object
The user home directory
25 26 27 28 29 |
# File 'lib/raykit/environment.rb', line 25 def self.home_dir return normalize_path(ENV['USERPROFILE']) if ENV.include?('USERPROFILE') normalize_path(ENV['HOME']) end |
.local_application_data ⇒ Object
65 66 67 |
# File 'lib/raykit/environment.rb', line 65 def self.local_application_data "#{ENV['USERPROFILE']}/AppData/Local".gsub('\\', '/') end |
.log_dir ⇒ Object
31 32 33 |
# File 'lib/raykit/environment.rb', line 31 def self.log_dir get_dev_dir('log') end |
.machine ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/raykit/environment.rb', line 53 def self.machine return ENV['COMPUTERNAME'] unless ENV['COMPUTERNAME'].nil? machine = `hostname` machine = machine.split('.')[0] if machine.include?('.') machine.strip end |
.normalize_path(name) ⇒ Object
Normalize a directory or filename to use forward slashes
9 10 11 |
# File 'lib/raykit/environment.rb', line 9 def self.normalize_path(name) name.gsub('\\', '/') end |
.root_dir ⇒ Object
The root directory for the development environment. May be set using the environment variable DEV_ROOT, otherwise defaults to the user home directory
16 17 18 19 20 21 22 |
# File 'lib/raykit/environment.rb', line 16 def self.root_dir if ENV['DEV_ROOT'].nil? Environment.home_dir else normalize_path(ENV['DEV_ROOT']) end end |
.user ⇒ Object
61 62 63 |
# File 'lib/raykit/environment.rb', line 61 def self.user ENV['USERNAME'] end |
.which(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/raykit/environment.rb', line 74 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 |