rosa-build/app/models/platform.rb

30 lines
858 B
Ruby
Raw Normal View History

2011-03-09 17:38:21 +00:00
class Platform < ActiveRecord::Base
has_many :projects, :dependent => :destroy
has_one :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
2011-03-09 17:38:21 +00:00
validate :name, :presence => true, :uniqueness => true
2011-03-10 13:38:50 +00:00
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
2011-03-09 17:38:21 +00:00
before_create :create_directory
2011-03-09 17:38:21 +00:00
2011-03-11 09:39:34 +00:00
def path
build_path(unixname)
2011-03-11 09:39:34 +00:00
end
2011-03-09 17:38:21 +00:00
protected
def build_path(dir)
File.join(APP_CONFIG['root_path'], dir)
end
def create_directory
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists
if new_record?
FileUtils.mkdir_p(path)
elsif unixname_changed?
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
end
2011-03-09 17:38:21 +00:00
end
end