Class: Environment

Inherits:
Hash
  • Object
show all
Defined in:
lib/base/environment.rb

Constant Summary collapse

@@debug =
false

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#execute, #to_html

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



5
6
7
8
9
# File 'lib/base/environment.rb', line 5

def initialize
  self[:home]=Environment.home
  self[:machine]=Environment.machine
  self[:user]=Environment.user
end

Class Method Details

.checkObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/base/environment.rb', line 48

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

.debugObject



11
12
13
# File 'lib/base/environment.rb', line 11

def self.debug
  @@debug
end

.dev_rootObject



40
41
42
43
44
45
46
# File 'lib/base/environment.rb', line 40

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



68
69
70
# File 'lib/base/environment.rb', line 68

def self.get_version text
  text.match(/(\d+\.\d+\.[\d\w]+)/)
end

.homeObject



15
16
17
18
19
20
21
22
23
# File 'lib/base/environment.rb', line 15

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

.infoObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/base/environment.rb', line 72

def self.info 
  puts "Environment"
  puts "  ruby version: #{`ruby --version`}"
  puts " ruby platform: #{RUBY_PLATFORM}"
  puts "      dev_root: #{Environment.dev_root}"
  puts "       machine: #{Environment.machine}"
  puts "          user: #{Environment.user}"
  puts "         debug: #{Environment.debug}"
  puts " "
  puts "Path Commands"
  ['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
  }
end

.machineObject



25
26
27
28
29
30
31
32
33
# File 'lib/base/environment.rb', line 25

def self.machine
   if !ENV['COMPUTERNAME'].nil? 
  return ENV['COMPUTERNAME']
end

   machine = `hostname`
   machine = machine.split('.')[0] if machine.include?('.')
return machine.strip
end

.userObject



35
36
37
38
# File 'lib/base/environment.rb', line 35

def self.user
  return ENV['USER'] if !ENV['USER'].nil?  #on Unix

  ENV['USERNAME']
end