2012-05-14 20:08:31 +01:00
|
|
|
class BuildList::Package < ActiveRecord::Base
|
|
|
|
PACKAGE_TYPES = %w(source binary)
|
|
|
|
|
|
|
|
belongs_to :build_list
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :platform
|
|
|
|
|
2013-09-11 16:16:18 +01:00
|
|
|
attr_accessor :epoch
|
2013-01-15 20:47:19 +00:00
|
|
|
attr_accessible :fullname, :name, :release, :version, :sha1
|
2012-05-14 20:08:31 +01:00
|
|
|
|
2012-08-24 16:19:26 +01:00
|
|
|
validates :build_list_id, :project_id, :platform_id, :fullname,
|
|
|
|
:package_type, :name, :release, :version,
|
|
|
|
:presence => true
|
2012-05-14 20:08:31 +01:00
|
|
|
validates :package_type, :inclusion => PACKAGE_TYPES
|
2013-01-10 11:16:08 +00:00
|
|
|
validates :sha1, :presence => true, :if => Proc.new { |p| p.build_list.new_core? }
|
2012-05-29 13:40:25 +01:00
|
|
|
|
2013-02-28 15:34:38 +00:00
|
|
|
default_scope order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC")
|
2012-11-28 06:04:40 +00:00
|
|
|
|
2012-08-24 16:19:26 +01:00
|
|
|
# Fetches only actual (last publised) packages.
|
|
|
|
scope :actual, where(:actual => true)
|
|
|
|
scope :by_platform, lambda {|platform| where(:platform_id => platform) }
|
|
|
|
scope :by_name, lambda {|name| where(:name => name) }
|
|
|
|
scope :by_package_type, lambda {|type| where(:package_type => type) }
|
2013-02-28 15:34:38 +00:00
|
|
|
scope :like_name, lambda {|name| where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present?}
|
2012-05-29 13:40:25 +01:00
|
|
|
|
|
|
|
def assignee
|
2012-08-24 16:19:26 +01:00
|
|
|
project.maintainer
|
|
|
|
end
|
2013-09-11 16:16:18 +01:00
|
|
|
|
|
|
|
def rpmvercmp(other)
|
|
|
|
RPM::C.rpmvercmp to_vre_epoch_zero, other.to_vre_epoch_zero
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# String representation in the form "e:v-r"
|
|
|
|
# @return [String]
|
|
|
|
# @note The epoch is included always. As 0 if not present
|
|
|
|
def to_vre_epoch_zero
|
|
|
|
evr = epoch.present? ? "#{epoch.to_i}:#{version}" : "0:#{version}"
|
|
|
|
evr << "-#{release}" if release.present?
|
|
|
|
evr
|
|
|
|
end
|
|
|
|
|
2012-05-14 20:08:31 +01:00
|
|
|
end
|