1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
class Package
include Elasticsearch::Persistence::Model
include Kkuleomi::Store::Model
include Kkuleomi::Store::Models::PackageImport
include Kkuleomi::Store::Models::PackageSearch
index_name "packages-#{Rails.env}"
raw_fields = {
type: 'keyword'
}
attribute :category, String, mapping: raw_fields
attribute :name, String, mapping: raw_fields
attribute :name_sort, String, mapping: raw_fields
attribute :atom, String, mapping: raw_fields
attribute :description, String, mapping: { type: 'text' }
attribute :longdescription, String, mapping: { type: 'text' }
attribute :homepage, String, default: [], mapping: raw_fields
attribute :license, String, mapping: raw_fields
attribute :licenses, String, default: [], mapping: raw_fields
attribute :herds, String, default: [], mapping: raw_fields
attribute :maintainers, Array, default: [], mapping: { type: 'object' }
attribute :useflags, Hash, default: {}, mapping: { type: 'object' }
attribute :metadata_hash, String, mapping: raw_fields
def category_model
@category_model ||= Category.find_by(:name, category)
end
def to_param
atom
end
# Are all of the versions of this package pending for removal?
#
# @return [Boolean] true, if all of the versions' masks look like a removal mask
def removal_pending?
versions.map(&:removal_pending?).uniq == [true]
end
def has_useflags?
useflags && !(useflags['local'].empty? && useflags['global'].empty? && useflags['use_expand'])
end
def versions
@versions ||= Version.find_all_by(:package, atom, sort: { sort_key: { order: 'asc' } })
end
def latest_version
versions.first
end
def version(version_str)
versions.each { |version| return version if version.version == version_str }
nil
end
# Does this package need a maintainer?
#
# @return [Boolean] true, if it is assigned to maintainer-needed or has no maintainers
def needs_maintainer?
(maintainers.size == 1 && maintainers.first['email'] == 'maintainer-needed@gentoo.org') ||
maintainers.empty? && herds.empty?
end
private
# Splits a license string into single licenses, stripping the permitted logic constructs
def split_license_str(str)
return [] unless str
str.split(/\s/).reject do |license|
(not license[0] =~ /[[:alpha:]]/) or license.end_with? '?'
end
end
end
|