Sha256: 6e8b8715f2e1f818167b6df28d84625c6805a27726a98cfac039e612c0a11451

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

class Environment < Hash

  def initialize
  end

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

  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

  def self.machine
     if !ENV['COMPUTERNAME'].nil? 
	   return ENV['COMPUTERNAME']
	 end

     machine = `hostname`
     machine = machine.split('.')[0] if machine.include?('.')
	 return machine.strip
   end

  def self.working_directory
    Rake.application.original_dir
  end

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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dev_tasks-0.0.44 lib/environment.rb
dev_tasks-0.0.43 lib/environment.rb
dev_tasks-0.0.42 lib/environment.rb
dev_tasks-0.0.40 lib/environment.rb
dev_tasks-0.0.39 lib/environment.rb