[refs #442] MassBuild data initialize refactor

This commit is contained in:
konstantin.grabar 2012-07-09 20:13:02 +04:00
parent c6600054d1
commit adc917ca3b
2 changed files with 15 additions and 16 deletions

View File

@ -10,13 +10,10 @@ class Platforms::MassBuildsController < Platforms::BaseController
skip_authorize_resource :platform, :only => [:create, :index]
def create
mass_build = MassBuild.new(
:platform_id => @platform.id,
:user_id => current_user.id,
:repositories => params[:repositories],
mass_build = @platform.mass_builds.new(:repositories => params[:repositories],
:arches => params[:arches],
:auto_publish => params[:auto_publish] || false
)
:auto_publish => params[:auto_publish] || false)
mass_build.user = current_user
authorize! :create, mass_build
if mass_build.save

View File

@ -12,6 +12,7 @@ class MassBuild < ActiveRecord::Base
validates_inclusion_of :auto_publish, :in => [true, false]
after_create :build_all
before_validation :set_data
COUNT_STATUSES = [
:build_lists,
@ -22,16 +23,6 @@ class MassBuild < ActiveRecord::Base
:build_error
]
def initialize(args = nil)
super
if new_record?
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
end
end
# ATTENTION: repositories and arches must be set before calling this method!
def build_all
platform.build_all(
@ -59,4 +50,15 @@ class MassBuild < ActiveRecord::Base
end
end
later :cancel_all, :queue => :clone_build
private
def set_data
if new_record?
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
end
end
end