Class: Publish

Inherits:
Array show all
Defined in:
lib/publish.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#add, #execute, #to_html

Class Method Details

.contextObject



62
63
64
65
# File 'lib/publish.rb', line 62

def self.context
 	dir =Rake.application.original_dir.gsub(Command.dev_root + '/','')
		return dir.split('/').first
end

.copy_files(files, dest) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/publish.rb', line 34

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

.relative_directoryObject



67
68
69
# File 'lib/publish.rb', line 67

def self.relative_directory
 	Rake.application.original_dir.gsub(Command.dev_root + '/' + Publish.context + '/','')
end

.svn_add_all(dir) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/publish.rb', line 46

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



54
55
56
57
58
59
60
61
# File 'lib/publish.rb', line 54

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

Instance Method Details

#updateObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/publish.rb', line 3

def update
	if(Internet.available?)
		Dir.glob('*.gemspec').each{|gemspec_file|
			add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
		}

		if(defined?(PUBLISH_PATH))
			if(PUBLISH_PATH.include?('svn://') && File.exists?('.svn') && defined?(ARTIFACTS))

				latestRev=Publish.svn_latest_revision 
				svn_publish_uri="#{PUBLISH_PATH}/#{Publish.relative_directory}-#{latestRev}"
				local_dir="#{Command.dev_root}/tmp/#{Publish.relative_directory}@#{latestRev}"
				FileUtils.mkdir_p(File.dirname(local_dir)) if(!File.exists?(File.dirname(local_dir)))
				dep_dir="#{Command.dev_root}/dep/#{Publish.relative_directory}@#{latestRev}"
				svn_info=`svn info #{svn_publish_uri} 2>&1`
				if(svn_info.include?('URL:'))
					#puts "#{svn_publish_uri} already exists."
				else
					#Console.debug "adding publish commands.."
					add "svn mkdir #{svn_publish_uri} --parents -m\"publish\""
					add "svn checkout #{svn_publish_uri} #{local_dir}"
					add "<%Publish.copy_files(ARTIFACTS,'#{local_dir}')%>"
					add "<%Publish.svn_add_all('#{local_dir}')%>"
					add "svn commit #{local_dir}@ -m\"publish\""
					add "<%FileUtils.rm_r('#{local_dir}')%>"
				end
			end
		end
	end
end