2012-05-18 16:12:51 +01:00
|
|
|
class MassBuild < ActiveRecord::Base
|
|
|
|
belongs_to :platform
|
2012-05-23 15:08:11 +01:00
|
|
|
belongs_to :user
|
|
|
|
has_many :build_lists, :dependent => :destroy
|
2012-05-18 16:12:51 +01:00
|
|
|
|
2012-05-21 11:18:29 +01:00
|
|
|
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
attr_accessor :repositories, :arches
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-05-29 14:44:30 +01:00
|
|
|
validates :platform_id, :arch_names, :name, :user_id, :repositories, :presence => true
|
|
|
|
validates_inclusion_of :auto_publish, :in => [true, false]
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
after_create :build_all
|
2012-05-25 16:56:26 +01:00
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
def initialize(args = nil)
|
|
|
|
super
|
|
|
|
|
|
|
|
if new_record?
|
|
|
|
rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
|
|
|
|
self.name = "#{Date.today.strftime("%d.%b")}-#{platform.name}(#{rep_names})"
|
|
|
|
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
|
2012-05-25 16:56:26 +01:00
|
|
|
end
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
|
|
|
|
2012-05-25 18:31:57 +01:00
|
|
|
# ATTENTION: repositories and arches must be set before calling this method!
|
|
|
|
def build_all
|
|
|
|
platform.delay.build_all(
|
|
|
|
:mass_build_id => self.id,
|
|
|
|
:user => self.user,
|
|
|
|
:repositories => self.repositories,
|
|
|
|
:arches => self.arches,
|
|
|
|
:auto_publish => self.auto_publish
|
|
|
|
)
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
|
|
|
end
|