rosa-build/app/models/project_to_repository.rb

37 lines
742 B
Ruby
Raw Normal View History

class ProjectToRepository < ActiveRecord::Base
belongs_to :project
belongs_to :repository
2011-10-19 14:14:53 +01:00
before_save :create_link
after_destroy :remove_link
after_create lambda {
project.xml_rpc_create
}
2011-10-19 14:14:53 +01:00
def path
build_path(project.unixname)
end
protected
def build_path(dir)
File.join(repository.path, dir)
end
def create_link
exists = File.exists?(path) && File.directory?(path)
raise "Symlink #{path} already exists" if exists
if new_record?
FileUtils.ln_s(project.path, path)
end
end
def remove_link
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} didn't exists" unless exists
FileUtils.rm_rf(path)
end
end