Class: Environment
Constant Summary collapse
- @@default =
nil
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
-
.check ⇒ Object
def self.remove directory if(File.exists?(directory)) begin FileUtils.rm_rf directory FileUtils.rm_r directory rescue end end end.
- .default ⇒ Object
-
.dev_root ⇒ Object
Begin LEGACY support.
- .get_version(text) ⇒ Object
- .info ⇒ Object
Instance Method Summary collapse
- #colorize? ⇒ Boolean
- #debug? ⇒ Boolean
- #get_env(key) ⇒ Object
- #has_work? ⇒ Boolean
- #home_dir ⇒ Object
-
#initialize(env = nil) ⇒ Environment
constructor
A new instance of Environment.
- #log_dir ⇒ Object
- #machine ⇒ Object
- #make_dir ⇒ Object
- #out(message) ⇒ Object
- #publish_dir ⇒ Object
-
#root_dir ⇒ Object
End LEGACY support.
- #set_env(key, value) ⇒ Object
- #show_success? ⇒ Boolean
- #user ⇒ Object
- #windows? ⇒ Boolean
- #working? ⇒ Boolean
- #wrk_dir ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(env = nil) ⇒ Environment
Returns a new instance of Environment.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/base/environment.rb', line 13 def initialize env=nil @output='' @env=Hash.new @env_aliases={'HOME' => ['USERPROFILE'], 'DEV_ROOT' => ['DEV_HOME','HOME','USERPROFILE'], 'USERNAME' => ['USER','USR'] } env.each{|k,v| @env[k.to_s]=v} if !env.nil? @@default=self if @@default.nil? end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/base/environment.rb', line 6 def output @output end |
Class Method Details
.check ⇒ Object
def self.remove directory
if(File.exists?(directory))
begin
FileUtils.rm_rf directory
FileUtils.rm_r directory
rescue
end
end
end
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/base/environment.rb', line 152 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 |
.default ⇒ Object
8 9 10 11 |
# File 'lib/base/environment.rb', line 8 def self.default @@default=Environment.new if @@default.nil? @@default end |
.dev_root ⇒ Object
Begin LEGACY support
25 26 27 |
# File 'lib/base/environment.rb', line 25 def self.dev_root default.root_dir end |
.get_version(text) ⇒ Object
171 172 173 |
# File 'lib/base/environment.rb', line 171 def self.get_version text text.match(/(\d+\.\d+\.[\d\w]+)/) end |
.info ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/base/environment.rb', line 175 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 |
Instance Method Details
#colorize? ⇒ Boolean
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/base/environment.rb', line 99 def colorize? colorize=true if windows? if(`gem list win32console`.include?('win32console')) require 'ansi/code' else colorize=false end end colorize end |
#debug? ⇒ Boolean
94 95 96 97 |
# File 'lib/base/environment.rb', line 94 def debug? return true if get_env('DEBUG')=='true' false end |
#get_env(key) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/base/environment.rb', line 75 def get_env key if(!@env.nil? && @env.has_key?(key)) return @env[key] end value = ENV[key] if(value.nil?) if(@env_aliases.has_key?(key)) @env_aliases[key].each{|akey| value=get_env(akey) if value.nil? } end end value end |
#has_work? ⇒ Boolean
116 117 118 |
# File 'lib/base/environment.rb', line 116 def has_work? true end |
#home_dir ⇒ Object
34 35 36 |
# File 'lib/base/environment.rb', line 34 def home_dir get_env('HOME').gsub('\\','/') end |
#log_dir ⇒ Object
38 39 40 41 42 |
# File 'lib/base/environment.rb', line 38 def log_dir dir="#{root_dir}/log/#{user}@#{machine}" FileUtils.mkdir_p dir if !File.exists? dir dir end |
#machine ⇒ Object
62 63 64 65 66 67 |
# File 'lib/base/environment.rb', line 62 def machine return ENV['COMPUTERNAME'] if !ENV['COMPUTERNAME'].nil? machine = `hostname` machine = machine.split('.')[0] if machine.include?('.') return machine.strip end |
#make_dir ⇒ Object
44 45 46 47 48 |
# File 'lib/base/environment.rb', line 44 def make_dir dir="#{root_dir}/make" FileUtils.mkdir_p dir if !File.exists? dir dir end |
#out(message) ⇒ Object
120 121 122 123 |
# File 'lib/base/environment.rb', line 120 def out puts if !get_env('SUPPRESS_CONSOLE_OUTPUT') @output=@output++'\n' end |
#publish_dir ⇒ Object
50 51 52 53 54 |
# File 'lib/base/environment.rb', line 50 def publish_dir dir="#{root_dir}/publish" FileUtils.mkdir_p dir if !File.exists? dir dir end |
#root_dir ⇒ Object
End LEGACY support
30 31 32 |
# File 'lib/base/environment.rb', line 30 def root_dir get_env('DEV_ROOT').gsub('\\','/') end |
#set_env(key, value) ⇒ Object
90 91 92 |
# File 'lib/base/environment.rb', line 90 def set_env key,value @env[key]=value end |
#show_success? ⇒ Boolean
125 126 127 |
# File 'lib/base/environment.rb', line 125 def show_success? true end |
#user ⇒ Object
69 70 71 72 73 |
# File 'lib/base/environment.rb', line 69 def user get_env('USERNAME') #return ENV['USER'] if !ENV['USER'].nil? #on Unix #ENV['USERNAME'] end |
#windows? ⇒ Boolean
129 130 131 |
# File 'lib/base/environment.rb', line 129 def windows? Gem.win_platform? end |
#working? ⇒ Boolean
111 112 113 114 |
# File 'lib/base/environment.rb', line 111 def working? return true if Rake.application.original_dir.include? wrk_dir false end |
#wrk_dir ⇒ Object
56 57 58 59 60 |
# File 'lib/base/environment.rb', line 56 def wrk_dir dir="#{root_dir}/wrk" FileUtils.mkdir_p dir if !File.exists? dir dir end |