rosa-build/app/models/product.rb

60 lines
1.7 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Product < ActiveRecord::Base
include Modules::Models::TimeLiving
belongs_to :platform
2012-11-06 14:13:16 +00:00
belongs_to :project
has_many :product_build_lists, :dependent => :destroy
ONCE_A_12_HOURS = 0
ONCE_A_DAY = 1
ONCE_A_WEEK = 2
AUTOSTART_STATUSES = [ONCE_A_12_HOURS, ONCE_A_DAY, ONCE_A_WEEK]
HUMAN_AUTOSTART_STATUSES = {
ONCE_A_12_HOURS => :once_a_12_hours,
ONCE_A_DAY => :once_a_day,
ONCE_A_WEEK => :once_a_week
}
validates :name, :presence => true, :uniqueness => {:scope => :platform_id}
validates :project_id, :presence => true
validates :main_script, :params, :length => { :maximum => 255 }
validates :autostart_status, :numericality => true,
:inclusion => {:in => AUTOSTART_STATUSES}, :allow_blank => true
2011-04-14 08:23:08 +01:00
2013-02-28 15:27:50 +00:00
scope :recent, order("#{table_name}.name ASC")
2011-04-14 08:23:08 +01:00
attr_accessible :name,
:description,
:project_id,
:main_script,
:params,
:platform_id,
:autostart_status
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)}
2013-02-27 21:55:30 +00:00
c.time_living = c.time_living.to_i / 60 # see: Modules::Models::TimeLiving#convert_time_living
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
def human_autostart_status
self.class.human_autostart_status(autostart_status)
end
def self.human_autostart_status(autostart_status)
I18n.t("layout.products.autostart_statuses.#{HUMAN_AUTOSTART_STATUSES[autostart_status]}")
end
# def self.autostart_iso_builds(autostart_status)
# Product.where(:autostart_status => autostart_status)
# end
end