Class: Environment

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Environment

Returns a new instance of Environment.



4
5
# File 'lib/environment.rb', line 4

def initialize
end

Class Method Details

.branch ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/environment.rb', line 48

def self.branch
  if(Environment.scm=='git')
    branches=`git branch`.split(/\n/)
 branches.each{|b|
   return b.gsub('*','').strip if b.include?('*')
 }
  end
end

.context ⇒ Object



39
40
41
42
# File 'lib/environment.rb', line 39

def self.context
  dir =Environment.working_directory.gsub(Environment.dev_root + '/','')
  return dir.split('/').first
end

.copy_if_newer(source, dest) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/environment.rb', line 57

def self.copy_if_newer(source,dest)
  if(File.exists?(source))
 if(File.exists?(dest))
if(File.mtime(source) > File.mtime(dest))
  FileUtils.cp(source,dest) 
      puts "copied " + Color.green + source + Color.clear + " to " + Color.green + dest + Color.clear
end
 else
   FileUtils.cp(source,dest)
puts "copied " + Color.green + source + Color.clear + " to " + Color.green + dest + Color.clear
 end
  end
end

.dev_root ⇒ Object



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

def self.dev_root
   ["DEV_HOME","DEV_ROOT","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?
   dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?

return dir
end

.execute(cmd) ⇒ Object



95
96
97
98
99
100
# File 'lib/environment.rb', line 95

def self.execute(cmd)
  timer=Timer.new
  puts "executing " + cmd
  puts `#{cmd}`
  puts timer.elapsed_str
end

.machine ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/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

.rake(directory, task, log) ⇒ Object



71
72
73
# File 'lib/environment.rb', line 71

def self.rake(directory)
  Environment.rake(directory,'default')
end

.relative_directory ⇒ Object



44
45
46
# File 'lib/environment.rb', line 44

def self.relative_directory
  Environment.working_directory.gsub(Environment.dev_root + '/' + Environment.context + '/','')
end

.scm ⇒ Object



7
8
9
10
11
# File 'lib/environment.rb', line 7

def self.scm
  return "git" if(Dir.exists?(".git"))
  return "svn" if(Dir.exists?(".svn"))
  "none"
end

.working_directory ⇒ Object



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

def self.working_directory
  Rake.application.original_dir
end