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 16:56:26 +01:00
|
|
|
attr_accessor :repositories_ids
|
|
|
|
|
|
|
|
validates :platform_id, :auto_publish, :arch_names, :name, :user_id, :repositories_ids, :presence => true
|
|
|
|
|
|
|
|
|
2012-05-18 16:12:51 +01:00
|
|
|
def build_all(opts={})
|
2012-05-23 15:08:11 +01:00
|
|
|
auto_publish = opts[:auto_publish] || false
|
2012-05-25 16:56:26 +01:00
|
|
|
if set_data(opts[:repositories], opts[:arches], auto_publish)
|
|
|
|
platform.delay.build_all opts.merge({:mass_build_id => self.id, :user => self.user})
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
|
|
|
|
2012-05-21 14:59:04 +01:00
|
|
|
private
|
2012-05-18 16:12:51 +01:00
|
|
|
|
2012-05-23 15:08:11 +01:00
|
|
|
def set_data(repositories_ids, arches, auto_publish=false)
|
2012-05-21 14:59:04 +01:00
|
|
|
rep_names = Repository.where(:id => repositories_ids).map(&:name).join(", ")
|
|
|
|
self.name = "#{Date.today.strftime("%d.%b")}-#{platform.name}(#{rep_names})"
|
2012-05-23 15:08:11 +01:00
|
|
|
self.arch_names = Arch.where(:id => arches).map(&:name).join(", ")
|
|
|
|
self.auto_publish = auto_publish
|
2012-05-25 16:56:26 +01:00
|
|
|
self.repositories_ids = repositories_ids
|
2012-05-23 15:08:11 +01:00
|
|
|
self.save
|
2012-05-18 16:12:51 +01:00
|
|
|
end
|
|
|
|
end
|