rosa-build/app/models/product.rb

62 lines
1.8 KiB
Ruby
Raw Normal View History

class Product < ActiveRecord::Base
include TimeLiving
include Autostart
include EventLoggable
belongs_to :platform
2012-11-06 14:13:16 +00:00
belongs_to :project
2014-01-21 04:51:49 +00:00
has_many :product_build_lists, dependent: :destroy
validates :name, presence: true,
uniqueness: { scope: :platform_id },
length: { maximum: 100 }
validates :project, presence: true
2014-01-21 04:51:49 +00:00
validates :main_script, :params, length: { maximum: 255 }
2011-04-14 08:23:08 +01:00
scope :recent, -> { order(:name) }
2011-04-14 08:23:08 +01:00
attr_accessible :name,
:description,
:project_id,
:main_script,
:params,
:platform_id,
2013-03-27 12:18:24 +00:00
:project_version
attr_readonly :platform_id
def full_clone(attrs = {})
2012-06-08 18:37:16 +01:00
dup.tap do |c|
attrs.each {|k,v| c.send("#{k}=", v)}
c.time_living = c.time_living.to_i / 60 # see: TimeLiving#convert_time_living
2013-02-27 21:55:30 +00:00
c.platform_id = nil
c.product_build_lists = []
2012-06-08 18:37:16 +01:00
c.updated_at = nil; c.created_at = nil
2011-11-03 00:32:01 +00:00
end
end
2013-03-22 17:17:40 +00:00
class << self
Autostart::HUMAN_AUTOSTART_STATUSES.each do |autostart_status, human_autostart_status|
2013-03-22 17:17:40 +00:00
define_method "autostart_iso_builds_#{human_autostart_status}" do
autostart_iso_builds autostart_status
end
end
end
def self.autostart_iso_builds(autostart_status)
2014-01-21 04:51:49 +00:00
Product.where(autostart_status: autostart_status).each do |product|
pbl = product.product_build_lists.new
2013-03-27 12:18:24 +00:00
[:params, :main_script, :project, :project_version].each do |k|
pbl.send "#{k}=", product.send(k)
end
owner = product.platform.owner
pbl.user = owner.is_a?(User) ? owner : owner.owner
pbl.autostarted = true
pbl.base_url = "http://#{product.platform.default_host}"
pbl.time_living = product.time_living / 60
pbl.save
end
end
end