Class: Katello::ModuleStream

Inherits:
Model
  • Object
show all
Includes:
Concerns::PulpDatabaseUnit, ScopedSearchExtensions
Defined in:
app/models/katello/module_stream.rb

Constant Summary collapse

CONTENT_TYPE =
"modulemd".freeze
MODULE_STREAM_DEFAULT_CONTENT_TYPE =
"modulemd_defaults".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::PulpDatabaseUnit

#backend_data, #library_repositories, #remove_from_repository

Methods inherited from Model

#destroy!

Class Method Details

.available_for_hosts(hosts) ⇒ Object



44
45
46
47
48
# File 'app/models/katello/module_stream.rb', line 44

def self.available_for_hosts(hosts)
  where("#{table_name}.id" => ::Katello::ModuleStream.joins(repositories: :content_facets).
        select("#{table_name}.id").
        merge(::Katello::Host::ContentFacet.where(host_id: hosts)))
end

.content_facet_association_classObject



40
41
42
# File 'app/models/katello/module_stream.rb', line 40

def self.content_facet_association_class
  ContentFacetApplicableModuleStream
end

.default_sortObject



36
37
38
# File 'app/models/katello/module_stream.rb', line 36

def self.default_sort
  order(:name)
end

.find_by_host_name(_key, operator, value) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'app/models/katello/module_stream.rb', line 78

def self.find_by_host_name(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{::Host::Managed.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.authorized("view_hosts").where(conditions).select(:id)
  if hosts.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Katello::ModuleStream.table_name}.id in (#{available_for_hosts(hosts).select(:id).to_sql})" }
  end
end

.find_by_module_spec(_key, _operator, value) ⇒ Object



88
89
90
91
92
93
94
95
# File 'app/models/katello/module_stream.rb', line 88

def self.find_by_module_spec(_key, _operator, value)
  spec = parse_module_spec(value)
  if spec.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Katello::ModuleStream.table_name}.id in (#{select(:id).where(spec).to_sql})" }
  end
end

.parse_module_spec(module_spec) ⇒ Object



67
68
69
70
71
72
# File 'app/models/katello/module_stream.rb', line 67

def self.parse_module_spec(module_spec)
  # NAME:STREAM:VERSION:CONTEXT:ARCH/PROFILE
  spec = module_spec.split("/").first
  name, stream, version, context, arch = spec.split(":")
  {:name => name, :stream => stream, :version => version, :context => context, :arch => arch}.compact
end

Instance Method Details

#content_view_filtersObject



74
75
76
# File 'app/models/katello/module_stream.rb', line 74

def content_view_filters
  Katello::ContentViewModuleStreamFilterRule.where(module_stream_id: self.id).eager_load(:filter).map(&:filter)
end

#module_specObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/katello/module_stream.rb', line 50

def module_spec
  # NAME:STREAM:VERSION:CONTEXT:ARCH
  items = []
  ["name", "stream", "version", "context", "arch"].each do |item|
    if attributes[item]
      items << attributes[item]
    else
      break
    end
  end
  items.join(":")
end

#module_spec_hashObject



63
64
65
# File 'app/models/katello/module_stream.rb', line 63

def module_spec_hash
  {:name => name, :stream => stream, :version => version, :context => context, :arch => arch, :pulp_id => pulp_id, :id => id}.compact
end