Class: Katello::ContentViewFilter
- Inherits:
-
Model
- Object
- ActiveRecord::Base
- Model
- Katello::ContentViewFilter
show all
- Defined in:
- app/models/katello/content_view_filter.rb
Constant Summary
collapse
- RPM =
Rpm::CONTENT_TYPE
- PACKAGE_GROUP =
PackageGroup::CONTENT_TYPE
- ERRATA =
Erratum::CONTENT_TYPE
- CONTENT_TYPES =
[RPM, PACKAGE_GROUP, ERRATA]
- CONTENT_OPTIONS =
{ _('Packages') => RPM, _('Package Groups') => PACKAGE_GROUP, _('Errata') => ERRATA }
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
#destroy!
Class Method Details
.applicable(repo) ⇒ Object
108
109
110
111
112
113
|
# File 'app/models/katello/content_view_filter.rb', line 108
def self.applicable(repo)
query = %{ (katello_content_view_filters.id in (select content_view_filter_id from katello_content_view_filters_repositories where repository_id = #{repo.id})) or
(katello_content_view_filters.id not in (select content_view_filter_id from katello_content_view_filters_repositories))
}
where(query).select("DISTINCT katello_content_view_filters.id")
end
|
.class_for(content_type) ⇒ Object
.create_for(content_type, options) ⇒ Object
103
104
105
106
|
# File 'app/models/katello/content_view_filter.rb', line 103
def self.create_for(content_type, options)
clazz = class_for(content_type)
clazz.create!(options)
end
|
.rule_class_for(filter) ⇒ Object
.rule_ids_for(filter) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/models/katello/content_view_filter.rb', line 85
def self.rule_ids_for(filter)
case filter.type
when ContentViewPackageFilter.name
filter.package_rule_ids
when ContentViewPackageGroupFilter.name
filter.package_group_rule_ids
when ContentViewErratumFilter.name
filter.erratum_rule_ids
else
fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
{ :content_type => filter.type, :content_types => CONTENT_TYPES.join(", ") }
end
end
|
Instance Method Details
#applicable_repos ⇒ Object
139
140
141
142
143
144
145
|
# File 'app/models/katello/content_view_filter.rb', line 139
def applicable_repos
if self.repositories.blank?
self.content_view.repositories
else
self.repositories
end
end
|
#as_json(options = {}) ⇒ Object
115
116
117
118
119
120
|
# File 'app/models/katello/content_view_filter.rb', line 115
def as_json(options = {})
super(options).update("content_view_label" => content_view.label,
"organization" => content_view.organization.label,
"repos" => repositories.collect(&:name),
"content" => content_type)
end
|
#filter_type ⇒ Object
99
100
101
|
# File 'app/models/katello/content_view_filter.rb', line 99
def filter_type
CONTENT_OPTIONS.key(content_type)
end
|
#original_packages=(_include_original) ⇒ Object
147
148
149
|
# File 'app/models/katello/content_view_filter.rb', line 147
def original_packages=(_include_original)
fail "setting original_packages not supported for #{self.class.name}"
end
|
45
46
47
|
# File 'app/models/katello/content_view_filter.rb', line 45
def params_format
{}
end
|
#resulting_products ⇒ Object
135
136
137
|
# File 'app/models/katello/content_view_filter.rb', line 135
def resulting_products
repositories.collect { |r| r.product }.uniq
end
|
#validate_content_view ⇒ Object
122
123
124
125
126
|
# File 'app/models/katello/content_view_filter.rb', line 122
def validate_content_view
if self.content_view.composite?
errors.add(:base, _("cannot contain filters if composite view"))
end
end
|
#validate_filter_repos(errors, content_view) ⇒ Object
128
129
130
131
132
133
|
# File 'app/models/katello/content_view_filter.rb', line 128
def validate_filter_repos(errors, content_view)
repo_diff = repositories - content_view.repositories
unless repo_diff.empty?
errors.add(:base, _("cannot contain filters whose repositories do not belong to this content view"))
end
end
|