Class: ForemanAnsibleDirector::AnsibleContent::SimpleAnsibleContentUnit
- Inherits:
-
Object
- Object
- ForemanAnsibleDirector::AnsibleContent::SimpleAnsibleContentUnit
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scm ⇒ Object
readonly
Returns the value of attribute scm.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_type ⇒ Object
readonly
Returns the value of attribute source_type.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#unit_type ⇒ Object
readonly
Returns the value of attribute unit_type.
-
#versions ⇒ Object
Returns the value of attribute versions.
Instance Method Summary collapse
- #collection_file ⇒ Object
-
#initialize(**kwargs) ⇒ SimpleAnsibleContentUnit
constructor
A new instance of SimpleAnsibleContentUnit.
- #role_url ⇒ Object
- #to_hash ⇒ Object
-
#unit_name ⇒ Object
Name of the content unit with respect to the namespace: “theforeman.operations” –> “operations”.
-
#unit_namespace ⇒ Object
Namespace of the content unit “theforeman.operations” –> “theforeman”.
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
#name ⇒ Object (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 |
#scm ⇒ Object (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 |
#source ⇒ Object (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_type ⇒ Object (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 |
#src ⇒ Object (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 |
#type ⇒ Object (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_type ⇒ Object (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 |
#versions ⇒ Object
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_file ⇒ Object
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_url ⇒ Object
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_hash ⇒ Object
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_name ⇒ Object
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_namespace ⇒ Object
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 |