Class: CycloneDX::CocoaPods::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclonedx/cocoapods/component.rb,
lib/cyclonedx/cocoapods/bom_builder.rb

Overview

Represents a software component in the CycloneDX BOM specification

A component is a self-contained unit of software that can be used as a building block in the architecture of a software system. Components can be of different types like libraries, frameworks, or applications.

Examples:

Creating a new component

component = Component.new(
  name: "AFNetworking",
  version: "4.0.1",
  type: "library"
)

Constant Summary collapse

VALID_COMPONENT_TYPES =
%w[application framework library container operating-system device firmware file].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version:, type:, group: nil, build_system: nil, vcs: nil) ⇒ Component

Returns a new instance of Component.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cyclonedx/cocoapods/component.rb', line 49

def initialize(name:, version:, type:, group: nil, build_system: nil, vcs: nil)
  # cocoapods is a special case to correctly build a purl
  package_type = type == 'cocoapods' ? 'cocoapods' : 'generic'
  @type = type == 'cocoapods' ? 'library' : type

  validate_attributes(name, version, @type, group)

  @group = group
  @name = name
  @version = version
  @build_system = build_system
  @vcs = vcs
  @bomref = build_purl(package_type, name, group, version)
end

Instance Attribute Details

#bomrefString (readonly)

The unique reference ID for this component in the BOM

Returns:

  • (String)

    the current value of bomref



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def bomref
  @bomref
end

#build_systemString? (readonly)

The build system information

Returns:

  • (String, nil)

    the current value of build_system



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def build_system
  @build_system
end

#groupString? (readonly)

The group/organization identifier of the component

Returns:

  • (String, nil)

    the current value of group



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def group
  @group
end

#nameString (readonly)

The name of the component

Returns:

  • (String)

    the current value of name



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def name
  @name
end

#typeString (readonly)

The type of component (must be one of VALID_COMPONENT_TYPES)

Returns:

  • (String)

    the current value of type



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def type
  @type
end

#vcsString? (readonly)

The version control system information

Returns:

  • (String, nil)

    the current value of vcs



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def vcs
  @vcs
end

#versionString (readonly)

The version string of the component

Returns:

  • (String)

    the current value of version



44
45
46
# File 'lib/cyclonedx/cocoapods/component.rb', line 44

def version
  @version
end

Instance Method Details

#add_to_bom(xml) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cyclonedx/cocoapods/bom_builder.rb', line 230

def add_to_bom(xml)
  xml.component(type: type, 'bom-ref': bomref) do
    xml.group group unless group.nil?
    xml.name_ name
    xml.version version

    if !build_system.nil? || !vcs.nil?
      xml.externalReferences do
        if build_system
          xml.reference(type: 'build-system') do
            xml.url build_system
          end
        end

        if vcs
          xml.reference(type: 'vcs') do
            xml.url vcs
          end
        end
      end
    end
    xml.purl bomref
  end
end

#to_json_componentObject



255
256
257
258
259
260
261
262
263
264
265
# File 'lib/cyclonedx/cocoapods/bom_builder.rb', line 255

def to_json_component
  {
    type: type,
    'bom-ref': bomref,
    group: group,
    name: name,
    version: version,
    purl: bomref,
    externalReferences: generate_json_external_references
  }.compact
end