Class: Environment
Class Method Summary collapse
- .check ⇒ Object
- .dev_root ⇒ Object
- .get_version(text) ⇒ Object
- .home ⇒ Object
- .machine ⇒ Object
- .user ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
Methods inherited from Hash
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
3 4 5 6 7 |
# File 'lib/environment.rb', line 3 def initialize self[:home]=Environment.home self[:machine]=Environment.machine self[:user]=Environment.user end |
Class Method Details
.check ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/environment.rb', line 42 def self.check #["ruby","svn","git","msbuild","candle","light"].each{|cmd| puts 'checking commands...' missing_command=false ['ruby --version','svn --version --quiet','git --version','msbuild /version','nuget','candle','light','gem --version'].each{|cmd| command=Command.new(cmd) command[:quiet]=true command[:ignore_failure]=true command.execute if(command[:exit_code] == 0) puts "#{cmd.split(' ')[0]} #{get_version(command[:output])}" else puts "#{cmd.split(' ')[0]} not found." missing_command=true end } puts "missing commands may be resolved by making sure that are installed and in PATH environment variable." if missing_command end |
.dev_root ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/environment.rb', line 34 def self.dev_root ["DEV_HOME","DEV_ROOT"].each {|v| return ENV[v].gsub('\\','/') unless ENV[v].nil? } dir=home return dir end |
.get_version(text) ⇒ Object
62 63 64 |
# File 'lib/environment.rb', line 62 def self.get_version text text.match(/(\d+\.\d+\.[\d\w]+)/) end |
.home ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/environment.rb', line 9 def self.home ["USERPROFILE","HOME"].each {|v| return ENV[v].gsub('\\','/') unless ENV[v].nil? } dir="~" dir=ENV["HOME"] unless ENV["HOME"].nil? dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil? return dir end |
.machine ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/environment.rb', line 19 def self.machine if !ENV['COMPUTERNAME'].nil? return ENV['COMPUTERNAME'] end machine = `hostname` machine = machine.split('.')[0] if machine.include?('.') return machine.strip end |
.user ⇒ Object
29 30 31 32 |
# File 'lib/environment.rb', line 29 def self.user return ENV['USER'] if !ENV['USER'].nil? #on Unix ENV['USERNAME'] end |