Class: ForemanAnsibleDirector::AnsibleContent::SimpleAnsibleContentUnit

Inherits:
Object
  • Object
show all
Defined in:
app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb

Overview

Simple representation of an Ansible content unit To be used in cases where AnsibleContentUnit is too heavy, i.e. Actions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ SimpleAnsibleContentUnit

Returns a new instance of SimpleAnsibleContentUnit.



11
12
13
14
15
16
17
18
19
20
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 11

def initialize(**kwargs)
  @unit_type = kwargs[:unit_type]
  @name = kwargs[:unit_name]
  @versions = kwargs[:unit_versions] || []
  @source_type = kwargs[:unit_source_type]
  @source = kwargs[:unit_source] || Setting[:ad_default_galaxy_url]
  @type = kwargs[:unit_type]
  @src = kwargs[:unit_src]
  @scm = kwargs[:unit_scm]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def name
  @name
end

#scmObject (readonly)

Returns the value of attribute scm.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def scm
  @scm
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def source
  @source
end

#source_typeObject (readonly)

Returns the value of attribute source_type.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def source_type
  @source_type
end

#srcObject (readonly)

Returns the value of attribute src.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def src
  @src
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def type
  @type
end

#unit_typeObject (readonly)

Returns the value of attribute unit_type.



9
10
11
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 9

def unit_type
  @unit_type
end

#versionsObject

Returns the value of attribute versions.



8
9
10
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 8

def versions
  @versions
end

Instance Method Details

#collection_fileObject



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
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 34

def collection_file
  return unless @unit_type == :collection
  if @versions.length.positive?
    YAML.dump(
      { 'collections' => @versions.map do |version|
        {
          'name' => @name,
          'version' => version,
          'source' => @source,
          'type' => @type,
        }.compact
      end }
    )
  else
    YAML.dump(
      { 'collections' =>
          [
            {
              'name' => @name,
              'source' => @source,
            },
          ] }
    )
  end
end

#role_urlObject



60
61
62
63
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 60

def role_url
  return unless @unit_type == :role
  "#{source}api/v1/roles/?namespace=#{unit_namespace}&name=#{unit_name}" # TODO: version restriction
end

#to_hashObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 65

def to_hash
  {
    unit_type: @unit_type,
    name: @name,
    versions: @versions,
    source: @source,
    type: @type,
    src: @src,
    scm: @scm,
  }
end

#unit_nameObject

Name of the content unit with respect to the namespace: “theforeman.operations” –> “operations”



24
25
26
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 24

def unit_name
  @name.split('.').last
end

#unit_namespaceObject

Namespace of the content unit “theforeman.operations” –> “theforeman”



30
31
32
# File 'app/lib/foreman_ansible_director/ansible_content/simple_ansible_content_unit.rb', line 30

def unit_namespace
  @name.split('.').first
end