2011-03-11 16:08:41 +00:00
|
|
|
class Repository < ActiveRecord::Base
|
|
|
|
belongs_to :platform
|
|
|
|
has_many :projects, :dependent => :destroy
|
|
|
|
|
|
|
|
validate :name, :presence => true, :uniqueness => true
|
2011-03-11 16:30:02 +00:00
|
|
|
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }
|
2011-03-11 16:08:41 +00:00
|
|
|
|
|
|
|
before_create :create_directory
|
|
|
|
|
|
|
|
def path
|
|
|
|
build_path(unixname)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def build_path(dir)
|
|
|
|
File.join(platform.path, dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
#TODO: Spec me
|
|
|
|
def create_directory
|
|
|
|
exists = File.exists?(path) && File.directory?(path)
|
|
|
|
raise "Directory #{path} already exists" if exists
|
|
|
|
if new_record?
|
|
|
|
FileUtils.mkdir_p(path)
|
2011-03-11 17:25:08 +00:00
|
|
|
%w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
|
2011-03-11 16:08:41 +00:00
|
|
|
elsif unixname_changed?
|
|
|
|
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|