Class: Environment
- Inherits:
-
Hash
- Object
- Hash
- Environment
- Defined in:
- lib/environment.rb
Class Method Summary collapse
- .branch ⇒ Object
- .context ⇒ Object
- .copy_if_newer(source, dest) ⇒ Object
- .dev_root ⇒ Object
- .execute(cmd) ⇒ Object
- .machine ⇒ Object
- .rake(directory, task, log) ⇒ Object
- .relative_directory ⇒ Object
- .scm ⇒ Object
- .scm_origin ⇒ Object
- .svn_latest_revision ⇒ Object
- .working_directory ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
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
71 72 73 74 75 76 77 78 |
# File 'lib/environment.rb', line 71 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
62 63 64 65 |
# File 'lib/environment.rb', line 62 def self.context dir =Environment.working_directory.gsub(Environment.dev_root + '/','') return dir.split('/').first end |
.copy_if_newer(source, dest) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/environment.rb', line 80 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
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/environment.rb', line 36 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
118 119 120 121 122 123 |
# File 'lib/environment.rb', line 118 def self.execute(cmd) timer=Timer.new puts "executing " + cmd puts `#{cmd}` puts timer.elapsed_str end |
.machine ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/environment.rb', line 48 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
94 95 96 |
# File 'lib/environment.rb', line 94 def self.rake(directory) Environment.rake(directory,'default') end |
.relative_directory ⇒ Object
67 68 69 |
# File 'lib/environment.rb', line 67 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 |
.scm_origin ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/environment.rb', line 13 def self.scm_origin if(Dir.exists?(".git")) `git remote show origin`.scan(/Fetch URL: ([\w:\/.-]+)/).each{|m| return m.first.to_s } end if(Dir.exists?(".svn")) `svn info`.scan(/URL: ([\w:\/.-]+)/).each{|m| return m.first.to_s } end "" end |
.svn_latest_revision ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/environment.rb', line 27 def self.svn_latest_revision if(Dir.exists?(".svn")) `svn info`.scan(/Last Changed Rev: ([\d]+)/).each{|m| return m.first.to_s } end "" end |
.working_directory ⇒ Object
58 59 60 |
# File 'lib/environment.rb', line 58 def self.working_directory Rake.application.original_dir end |