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.



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

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

Class Method Details

.checkObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/base/environment.rb', line 62

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','nunit-console','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

.configurationObject



30
31
32
33
34
35
36
37
# File 'lib/base/environment.rb', line 30

def self.configuration
  config="#{Environment.home}/dev.config.rb"
  if(!File.exists?(config))
    text=IO.read("#{File.dirname(__FILE__)}/../dev.config.rb")
    File.open(config,'w'){|f|f.write(text)}
  end
  config
end

.debugObject



16
17
18
# File 'lib/base/environment.rb', line 16

def self.debug
  @@debug
end

.dev_rootObject



54
55
56
57
58
59
60
# File 'lib/base/environment.rb', line 54

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



82
83
84
# File 'lib/base/environment.rb', line 82

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

.homeObject



20
21
22
23
24
25
26
27
28
# File 'lib/base/environment.rb', line 20

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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/base/environment.rb', line 86

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 " configuration: #{Environment.configuration}"
  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].fix(14)} #{get_version(command[:output])}"
    else
      puts "#{cmd.split(' ')[0].fix(14)} not found."
        missing_command=true
    end
  }
end

.machineObject



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

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



49
50
51
52
# File 'lib/base/environment.rb', line 49

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