Module: Repository::ClassMethods

Includes:
Constants
Included in:
Repository
Defined in:
app/models/repository.rb

Constant Summary

Constants included from Constants

Repository::Constants::Error_classification, Repository::Constants::README_start_text, Repository::Constants::Root_directory, Repository::Constants::Source, Repository::Constants::Temporary

Instance Method Summary collapse

Instance Method Details

#create_empty(path) ⇒ Object

git_command


32
33
34
35
36
37
38
39
40
41
# File 'app/models/repository.rb', line 32

def create_empty(path)
	Dir.mkdir(path)
	if File.exists?(path) then
		ShellCommands.new([['cd', path], '&&', ['git', 'init']])
		new_repository=Repository.new(path)
	else
		raise "Repository.create_empty failed: File.exists?(#{path})=#{File.exists?(path)}"
	end #if
	new_repository
end

#create_if_missing(path) ⇒ Object

replace_or_create


52
53
54
55
56
57
58
# File 'app/models/repository.rb', line 52

def create_if_missing(path)
	if File.exists?(path) then
		Repository.new(path)
	else
		create_empty(path)
	end #if
end

#create_test_repository(path = data_sources_directory?+Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")) ⇒ Object

create_if_missing


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/repository.rb', line 59

def create_test_repository(path=data_sources_directory?+Time.now.strftime("%Y-%m-%d %H:%M:%S.%L"))
	replace_or_create(path)
	if File.exists?(path) then
		new_repository=Repository.new(path)
		IO.write(path+'/README', README_start_text+"\n") # two consecutive slashes = one slash
		new_repository.git_command('add README')
		new_repository.git_command('commit -m "create_empty initial commit of README"')
		new_repository.git_command('branch passed')
	else
		raise "Repository.create_empty failed: File.exists?(#{path})=#{File.exists?(path)}"
	end #if
	new_repository
end

#delete_existing(path) ⇒ Object

create_empty


42
43
44
45
# File 'app/models/repository.rb', line 42

def delete_existing(path)
# @see http://www.ruby-doc.org/stdlib-1.9.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove
	FileUtils.remove_entry_secure(path) #, force = false)
end

#git_command(git_command, repository_dir) ⇒ Object


29
30
31
# File 'app/models/repository.rb', line 29

def git_command(git_command, repository_dir)
	ShellCommands.new('git '+ShellCommands.assemble_command_string(git_command), :chdir=>repository_dir)
end

#replace_or_create(path) ⇒ Object

delete_existing


46
47
48
49
50
51
# File 'app/models/repository.rb', line 46

def replace_or_create(path)
	if File.exists?(path) then
		delete_existing(path)
	end #if
	create_empty(path)
end