Module: Windoo::Mixins::Patch::Component

Included in:
Patch
Defined in:
lib/windoo/mixins/patch/component.rb

Overview

An module that manages the Component in a Patch.

Even though ‘components’ is plural, and they come from the server in an Array, at the moment there can only be one per Paatch.

This module hides that confusion and allows you to work with just one

If there’s already an component, you can access it from the #component getter, and use that to directly update its values.

Instance Method Summary collapse

Instance Method Details

#add_component(name:, version:) ⇒ Integer

Add a component to this Patch. After its created, you can add criteria to it.

NOTE: There can be only one per v. You will get an error if one already exists.

Parameters:

  • name (String)

    The name of the component. Usually the same as the name of the Software Title it is associated with

  • version (String)

    The version of the componen. Usually the same as the version of the Patch if it associated with

Returns:

  • (Integer)

    The id of the new Extension Attribute



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/windoo/mixins/patch/component.rb', line 63

def add_component(name:, version:)
  if @component
    raise Windoo::AlreadyExistsError,
          'This Patch already has a Component. Either delete it before creating a new one, or update the existing one.'
  end

  @component = Windoo::Component.create(
    container: self,
    cnx: cnx,
    name: name,
    version: version
  )

  @component.componentId
end

#delete_componentInteger

Delete the component from this Patch

Returns:

  • (Integer)

    The id of the deleted Extension Attribute



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/windoo/mixins/patch/component.rb', line 83

def delete_component
  return unless @component

  deleted_id = @component.delete
  @component = nil

  # patches without a component are not valid
  # so must be disabled
  container.disable

  deleted_id
end

#initialize(**init_data) ⇒ Object

Construcor



33
34
35
36
37
38
39
40
41
42
# File 'lib/windoo/mixins/patch/component.rb', line 33

def initialize(**init_data)
  super
  @component =
    if @init_data[:components]&.first
      Windoo::Component.instantiate_from_container(
        container: self,
        **@init_data[:components].first
      )
    end
end