rosa-build/app/models/product_build_list.rb

57 lines
1.6 KiB
Ruby
Raw Normal View History

class ProductBuildList < ActiveRecord::Base
include TimeLiving
include FileStoreClean
include UrlHelper
include EventLoggable
include ProductBuildLists::Statusable
include ProductBuildLists::AbfWorkerable
2016-04-29 15:10:30 +01:00
include EventLoggable
2012-11-06 14:13:16 +00:00
LIVE_TIME = 2.week # for autostart
MAX_LIVE_TIME = 3.month # for manual start;
belongs_to :product
2012-11-06 14:13:16 +00:00
belongs_to :project
belongs_to :user
2012-11-06 14:13:16 +00:00
# field "not_delete" can be changed only if build has been completed
before_validation -> { self.not_delete = false unless build_completed?; true }
2014-11-25 17:33:54 +00:00
validates :product, :product_id,
:project, :project_id,
:main_script,
2014-11-25 17:33:54 +00:00
presence: true
2014-01-21 04:51:49 +00:00
validates :main_script, :params, length: { maximum: 255 }
attr_accessor :base_url, :product_name
attr_readonly :product_id
2012-11-08 21:39:42 +00:00
serialize :results, Array
scope :default_order, -> { order(updated_at: :desc) }
scope :for_user, -> (user) { where(user_id: user.id) }
scope :scoped_to_product_name, -> (product_name) {
joins(:product).where('products.name LIKE ?', "%#{product_name}%") if product_name.present?
}
scope :recent, -> { order(updated_at: :desc) }
scope :outdated, -> {
where(not_delete: false).
where("(#{table_name}.created_at < ? AND #{table_name}.autostarted is TRUE) OR #{table_name}.created_at < ?",
Time.now - LIVE_TIME, Time.now - MAX_LIVE_TIME)
}
after_initialize :init_project, if: :new_record?
def event_log_message
2014-01-21 04:51:49 +00:00
{product: product.name}.inspect
end
protected
def init_project
self.project ||= product.try(:project)
end
end