Class: ForemanAnsibleDirector::AnsibleContent::ParsedAnsibleContentUnit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unit_type, **kwargs) ⇒ ParsedAnsibleContentUnit

Returns a new instance of ParsedAnsibleContentUnit.



8
9
10
11
12
13
14
15
16
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 8

def initialize(unit_type, **kwargs)
  @unit_type = unit_type
  @name = kwargs['name']
  @version = kwargs['version']
  @source = kwargs['source'] || Setting[:ad_default_galaxy_url]
  @type = kwargs['type']
  @src = kwargs['src']
  @scm = kwargs['scm']
end

Instance Attribute Details

#scmObject (readonly)

Returns the value of attribute scm.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def scm
  @scm
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def source
  @source
end

#srcObject (readonly)

Returns the value of attribute src.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def src
  @src
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def type
  @type
end

#unit_typeObject (readonly)

Returns the value of attribute unit_type.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def unit_type
  @unit_type
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 6

def version
  @version
end

Instance Method Details

#collection_fileObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 53

def collection_file
  return unless @unit_type == :collection
  YAML.dump(
    { 'collections' =>
       [
         {
           'name' => @name,
           'version' => @version,
           'source' => @source,
           'type' => @type,
         }.compact,
       ] }
  )
end

#git?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 18

def git?
  case @unit_type
  when :role
    true if @scm == 'git'
  when :collection
    true if @type == 'git'
  end
end

#nameObject

Full name of the content unit “theforeman.operations” –> “theforeman.operations”



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

def name
  return @name if @name
  infer_name_from_source
end

#role_urlObject



46
47
48
49
50
51
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 46

def role_url
  return unless @unit_type == :role
  split = @name.split('.')
  # TODO: global param, version restriction
  "https://galaxy.ansible.com/api/v1/roles/?owner__username=#{split[0]}&name=#{split[1]}"
end

#unit_nameObject

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



36
37
38
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 36

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

#unit_namespaceObject

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



42
43
44
# File 'app/lib/foreman_ansible_director/ansible_content/parsed_ansible_content_unit.rb', line 42

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