Class: ForemanAnsibleDirector::AnsibleCollection

Inherits:
ContentUnit show all
Defined in:
app/models/foreman_ansible_director/ansible_collection.rb

Instance Method Summary collapse

Methods inherited from ContentUnit

#collection?, #full_name, polymorphic_name, #role?, table_name

Methods inherited from AnsibleDirectorModel

#flatten_errors, table_name

Instance Method Details

#requirements_file(simple_content_unit = nil, subtractive: false) ⇒ Object



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
# File 'app/models/foreman_ansible_director/ansible_collection.rb', line 12

def requirements_file(simple_content_unit = nil, subtractive: false)
  units = []
  content_unit_versions.where(source_type: 'galaxy').find_each do |content_version|
    units.append(
      'name' => "#{namespace}.#{name}",
      'version' => content_version.version,
      'source' => content_version.source
    )
  end

  if simple_content_unit
    if subtractive
      units = units.reject { |unit| simple_content_unit.versions.include?(unit['version']) }
    elsif simple_content_unit.versions&.length&.positive?
      simple_content_unit.versions.each do |version|
        units.append(
          'name' => simple_content_unit.name,
          'version' => version,
          'source' => simple_content_unit.source
        )
      end
    else
      units.append(
        'name' => simple_content_unit.name,
        'source' => simple_content_unit.source
      )

    end
  end

  YAML.dump({ 'collections' => units })
end