Class: Environment
Constant Summary collapse
- @@debug =
false- @@development_root =
nil
Class Method Summary collapse
- .check ⇒ Object
- .configuration ⇒ Object
- .debug ⇒ Object
- .dev_root ⇒ Object
- .get_latest_mtime(directory) ⇒ Object
- .get_version(text) ⇒ Object
- .home ⇒ Object
- .info ⇒ Object
- .machine ⇒ Object
- .remove(directory) ⇒ Object
- .set_development_root(value) ⇒ 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.
11 12 13 14 15 |
# File 'lib/base/environment.rb', line 11 def initialize self[:home]=Environment.home self[:machine]=Environment.machine self[:user]=Environment.user end |
Class Method Details
.check ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/base/environment.rb', line 86 def self.check 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 |
.configuration ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/base/environment.rb', line 41 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 |
.debug ⇒ Object
27 28 29 |
# File 'lib/base/environment.rb', line 27 def self.debug @@debug end |
.dev_root ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/base/environment.rb', line 75 def self.dev_root if(!@@development_root.nil?) return @@development_root end ["DEV_HOME","DEV_ROOT"].each {|v| return ENV[v].gsub('\\','/') unless ENV[v].nil? } dir=home return dir end |
.get_latest_mtime(directory) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/base/environment.rb', line 134 def self.get_latest_mtime directory mtime=nil Dir.chdir(directory) do Dir.glob('**/*.*').each{|f| mtime=File.mtime(f) if mtime.nil? || File.mtime(f) > mtime } end mtime end |
.get_version(text) ⇒ Object
105 106 107 |
# File 'lib/base/environment.rb', line 105 def self.get_version text text.match(/(\d+\.\d+\.[\d\w]+)/) end |
.home ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/base/environment.rb', line 31 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 |
.info ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/base/environment.rb', line 109 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 |
.machine ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/base/environment.rb', line 50 def self.machine if !ENV['COMPUTERNAME'].nil? return ENV['COMPUTERNAME'] end machine = `hostname` machine = machine.split('.')[0] if machine.include?('.') return machine.strip end |
.remove(directory) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/base/environment.rb', line 60 def self.remove directory if(File.exists?(directory)) begin FileUtils.rm_rf directory FileUtils.rm_r directory rescue end end end |
.set_development_root(value) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/base/environment.rb', line 17 def self.set_development_root value @@development_root=value if(!value.nil?) FileUtils.mkdir_p value if(!File.exists?(value)) ['bin','data','log','make','publish','test'].each{|dir| #FileUtils.mkdir_p("#{value}/#{dir}") if !File.exists? "#{value}/#{dir}" } end end |
.user ⇒ Object
70 71 72 73 |
# File 'lib/base/environment.rb', line 70 def self.user return ENV['USER'] if !ENV['USER'].nil? #on Unix ENV['USERNAME'] end |