rosa-build/app/models/repository.rb

54 lines
1.8 KiB
Ruby
Raw Normal View History

class Repository < ActiveRecord::Base
belongs_to :platform
belongs_to :owner, :polymorphic => true
has_many :projects, :through => :project_to_repositories #, :dependent => :destroy
has_many :project_to_repositories, :validate => true, :dependent => :destroy
has_many :relations, :as => :target, :dependent => :destroy
has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy
has_many :members, :through => :objects, :source => :object, :source_type => 'User'
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true
2011-11-22 19:21:09 +00:00
validates :unixname, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-z0-9_]+$/ }
# validates :platform_id, :presence => true # if you uncomment this platform clone will not work
scope :recent, order("name ASC")
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
before_destroy :xml_rpc_destroy
attr_accessible :name, :unixname #, :platform_id
2011-11-03 00:32:01 +00:00
def full_clone(attrs) # owner
clone.tap do |c| # dup
c.attributes = attrs
c.updated_at = nil; c.created_at = nil # :id = nil
c.projects = projects
end
2011-03-11 17:38:28 +00:00
end
include Modules::Models::Owner
protected
2011-10-18 16:00:06 +01:00
2011-04-07 10:27:50 +01:00
def xml_rpc_create
2011-04-14 12:24:41 +01:00
result = BuildServer.create_repo unixname, platform.unixname
2011-04-07 10:27:50 +01:00
if result == BuildServer::SUCCESS
return true
else
2011-10-27 23:42:56 +01:00
raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}."
2011-04-07 10:27:50 +01:00
end
end
def xml_rpc_destroy
2011-04-14 12:24:41 +01:00
result = BuildServer.delete_repo unixname, platform.unixname
2011-04-07 10:27:50 +01:00
if result == BuildServer::SUCCESS
return true
else
raise "Failed to delete repository #{name} inside platform #{platform.name}."
end
end
end