Module: Katello::SyncManagementHelper::RepoMethods

Included in:
Api::V2::SyncStatusController
Defined in:
app/helpers/katello/sync_management_helper.rb

Instance Method Summary collapse

Instance Method Details

#arches(arch_repos, parent_id) ⇒ Object

returns all archs in hash representation



79
80
81
82
83
84
85
# File 'app/helpers/katello/sync_management_helper.rb', line 79

def arches(arch_repos, parent_id)
  collect_arches(arch_repos).map do |arch, repos|
    arch_id = "#{parent_id}-#{arch}"
    { :name => arch, :id => arch_id, :type => "arch", :children => [],
      :repos => repos.map { |r| format_repo(r) } }
  end
end

#collect_arches(repos) ⇒ Object

converts array of repositories to hash using architecture as key

collect_arches [<#repo1 arch:i386>, <#repo2 arch:i386>, <#repo3 arch:x86_64>] # =>

{'i386' => [<#repo1>, <#repo2>], 'x86_64' => [#<repo3>]}


104
105
106
# File 'app/helpers/katello/sync_management_helper.rb', line 104

def collect_arches(repos)
  repos.group_by(&:arch)
end

#collect_minor(repos) ⇒ Object

converts array of repositories to hash using minor as key

repositories having nil minor are returned as a second variable, if none such is present, empty array is returned

collect_arches [<#repo1 minor:1>, <#repo2 minor:2>, <#repo3 minor:nil>] # =>

[{'1' => [<#repo1>], '2' => <#repo2>]}, [#<repo3>]]


94
95
96
97
98
# File 'app/helpers/katello/sync_management_helper.rb', line 94

def collect_minor(repos)
  result               = repos.group_by(&:minor)
  result_without_minor = result.delete(nil)
  [result, result_without_minor || []]
end

#collect_repos(products, env, include_feedless = true) ⇒ Object

returns all repos in hash representation with minors and arch children included



60
61
62
63
64
65
66
67
# File 'app/helpers/katello/sync_management_helper.rb', line 60

def collect_repos(products, env, include_feedless = true)
  products.map do |prod|
    minor_repos, repos_without_minor = collect_minor(prod.repos(env, nil, include_feedless))
    { :name => prod.name, :object => prod, :id => prod.id, :type => "product",
      :repos => repos_without_minor.map { |r| format_repo(r) },
      :children => minors(minor_repos, prod.id), :organization => prod.organization.name }
  end
end

#filter_empty_nodes(nodes) ⇒ Object

Filter out nodes with no repositories



49
50
51
52
53
54
55
56
57
# File 'app/helpers/katello/sync_management_helper.rb', line 49

def filter_empty_nodes(nodes)
  nodes.select { |node| repos?(node) }.map do |node|
    if node[:children].present?
      node.merge(:children => filter_empty_nodes(node[:children]))
    else
      node
    end
  end
end

#format_repo(repo) ⇒ Object

Format a repository as a hash for the API



33
34
35
36
37
38
39
# File 'app/helpers/katello/sync_management_helper.rb', line 33

def format_repo(repo)
  {
    :id => repo.id,
    :name => repo.name,
    :type => "repo",
  }
end

#minors(minor_repos, product_id) ⇒ Object

returns all minors in hash representation with arch children included



70
71
72
73
74
75
76
# File 'app/helpers/katello/sync_management_helper.rb', line 70

def minors(minor_repos, product_id)
  minor_repos.map do |minor, repos|
    minor_id = "#{product_id}-#{minor}"
    { :name => minor, :id => minor_id, :type => "minor",
      :children => arches(repos, minor_id), :repos => [] }
  end
end

#pprint_collection(coll) ⇒ Object

Used for debugging collect_repos output



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/katello/sync_management_helper.rb', line 109

def pprint_collection(coll)
  coll.each do |prod|
    Rails.logger.error prod[:name]
    prod[:children].each do |major|
      Rails.logger.error major[:name]
      major[:children].each do |minor|
        Rails.logger.error minor[:name]
        minor[:children].each do |arch|
          Rails.logger.error arch[:repos].length
        end
      end
    end
  end
end

#repos?(node) ⇒ Boolean

Recursively check if a node has any repositories

Returns:

  • (Boolean)


42
43
44
45
46
# File 'app/helpers/katello/sync_management_helper.rb', line 42

def repos?(node)
  return true if node[:repos].present? && node[:repos].any?
  return false if node[:children].blank?
  node[:children].any? { |child| repos?(child) }
end