Class: Environment

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

Overview

require ‘dev_environment’

Class Method Summary collapse

Class Method Details

.branchObject



72
73
74
75
76
77
78
79
# File 'lib/environment.rb', line 72

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

.contextObject



63
64
65
66
# File 'lib/environment.rb', line 63

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

.copy(src, dest) ⇒ Object



11
12
13
14
# File 'lib/environment.rb', line 11

def self.copy src,dest
  FileUtils.mkdir_p File.dirname(dest) if !File.exists?(File.dirname(dest))
 FileUtils.cp(src,dest)
end

.copy_files(files, dest) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/environment.rb', line 16

def self.copy_files files,dest
  Console.debug("Environment.copy_files([#{files.to_s}],'#{dest}'')")
  files.each{|f|
 if(File.directory?(dest))
   dest_file = "#{dest}/#{f}"
   Console.debug "copying #{f} to #{dest_file}"
FileUtils.mkdir_p(File.dirname(dest_file)) if(!File.exists?(File.dirname(dest_file)))
   FileUtils.cp(f,dest_file)
 end
	}
end

.copy_if_newer(source, dest) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/environment.rb', line 81

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

.rake(directory, task, log) ⇒ Object



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

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

.relative_directoryObject



68
69
70
# File 'lib/environment.rb', line 68

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

.scmObject

S< Hash#.class_eval do #< Hash do



5
6
7
8
9
# File 'lib/environment.rb', line 5

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

.scm_originObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/environment.rb', line 36

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_add_all(dir) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/environment.rb', line 28

def self.svn_add_all dir
	Dir.chdir(dir) do
 Dir.glob('**/*').each{|f|
   puts `svn add #{f} --parents` if(!File.directory?(f))
 }
	end
end

.svn_latest_revisionObject



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

def self.svn_latest_revision
  if(Dir.exists?(".svn"))
 `svn info`.scan(/Last Changed Rev: ([\d]+)/).each{|m|
   return m.first.to_s
 }
	end
	"0"
end

.working_directoryObject



59
60
61
# File 'lib/environment.rb', line 59

def self.working_directory
  Rake.application.original_dir
end