rosa-build/app/models/platform.rb

17 lines
557 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_validation :generate_unixname
2011-03-09 17:38:21 +00:00
protected
def generate_unixname
2011-03-10 13:38:50 +00:00
self.unixname = name.gsub(/[^a-zA-Z0-9\-.]/, '-')
#TODO: Fix non-unique unixname
2011-03-09 17:38:21 +00:00
end
end