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
63 64 65 66 |
# File 'lib/raykit/environment.rb', line 63 def self.admin? rights=%x[whoami /priv] return rights.include?('SeCreateGlobalPrivilege') end |
.get_dev_dir(name) ⇒ Object
Get, and create if it does not exist, a specific development directory
32 33 34 35 36 |
# File 'lib/raykit/environment.rb', line 32 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
42 43 44 45 46 |
# File 'lib/raykit/environment.rb', line 42 def self.get_dir_size(dir) Dir.glob(File.join(dir, '**', '*')) .map{ |f| File.size(f) } .inject(:+) end |
.get_work_dir(url) ⇒ Object
38 39 40 |
# File 'lib/raykit/environment.rb', line 38 def self.get_work_dir(url) Raykit::Environment::get_dev_dir('work') +'/' + url.gsub('://','/').gsub('.git','') end |
.home_dir ⇒ Object
The user home directory
23 24 25 26 |
# File 'lib/raykit/environment.rb', line 23 def self.home_dir return normalize_path(ENV["USERPROFILE"]) if(ENV.include?("USERPROFILE")) normalize_path(ENV['HOME']) end |
.local_application_data ⇒ Object
59 60 61 |
# File 'lib/raykit/environment.rb', line 59 def self.local_application_data return "#{ENV['USERPROFILE']}/AppData/Local".gsub('\\','/') end |
.log_dir ⇒ Object
28 29 30 |
# File 'lib/raykit/environment.rb', line 28 def self.log_dir return get_dev_dir('log') end |
.machine ⇒ Object
48 49 50 51 52 53 |
# File 'lib/raykit/environment.rb', line 48 def self.machine return ENV['COMPUTERNAME'] if !ENV['COMPUTERNAME'].nil? machine = `hostname` machine = machine.split('.')[0] if machine.include?('.') return machine.strip end |
.normalize_path(name) ⇒ Object
Normalize a directory or filename to use forward slashes
7 8 9 |
# File 'lib/raykit/environment.rb', line 7 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
14 15 16 17 18 19 20 |
# File 'lib/raykit/environment.rb', line 14 def self.root_dir if(ENV['DEV_ROOT'].nil?) Environment::home_dir else normalize_path(ENV['DEV_ROOT']) end end |
.user ⇒ Object
55 56 57 |
# File 'lib/raykit/environment.rb', line 55 def self.user ENV['USERNAME'] end |
.which(name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/raykit/environment.rb', line 68 def self.which(name) if (File.exists?(name)) return name end ["",".exe",".bat",".cmd"].each{|ext| aname = name + ext if (File.exists?(aname)) return aname end ENV['PATH'].split(File::PATH_SEPARATOR).each{|path| apath = (path.gsub("\\","/") + '/' + aname).gsub("//","/") if(File.exists?(apath)) return apath end } } '' end |