Skip to content

Commit 378f62e

Browse files
committed
🎨 modernize for 2025
### Added - `CHANGELOG.md` file to document notable changes in keep-a-changelog format - `Cyclonedx::BomHelpers` module to house helper methods, replacing global methods - `Cyclonedx::BomBuilder` class, replacing `Bombuilder` (note the capitalization change) - `Cyclonedx::BomComponent` class, replacing `BomComponent` - `Cyclonedx::Ruby::Version::VERSION` constant to hold the version number (also available as `Cyclonedx::VERSION`) - `Cyclonedx::Ruby::Deprecation` module to help manage deprecations ### Changed - Updated gemspec metadata for clarity and consistency - Modernized Rakefile, dotfiles, and test setup - `LICENSE` => `LICENSE.txt` to simplify parsing consistency on various platforms and tools - `cucumber` v8 => v10 - `aruba` v2.1 => v2.2 ### Deprecated - `BomComponent` => `Cyclonedx::BomComponent` - `Bombuilder` => `Cyclonedx::BomBuilder` (note the capitalization change) - `Object.purl` => `Cyclonedx::BomHelpers.purl` - `Object.random_urn_uuid` => `Cyclonedx::BomHelpers.random_urn_uuid` - `Object.build_bom` => `Cyclonedx::BomHelpers.build_bom` - `Object.build_json_bom` => `Cyclonedx::BomHelpers.build_json_bom` - `Object.build_bom_xml` => `Cyclonedx::BomHelpers.build_bom_xml` - `Object.get_gem` => `Cyclonedx::BomHelpers.get_gem` ### Fixed - `Nokogiri::XML::Builder` context relies on `method_missing` - Globally defined `Object#purl` conflicted with `<purl>`. - Moved to `Cyclonedx::BomHelpers.purl` to avoid conflict in v2.0.0 (along with all other global methods) - Fixed existing usage via the built-in Nokogiri workaround of adding an underscore `purl_` - The XML tag is unchanged as `<purl>` Signed-off-by: Peter H. Boling <[email protected]>
1 parent bd7f47f commit 378f62e

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ Please file a bug if you notice a violation of semantic versioning.
5050

5151
### Fixed
5252

53+
- `Nokogiri::XML::Builder` context relies on `method_missing`
54+
- Globally defined `Object#purl` conflicted with `<purl>`.
55+
- Moved to `Cyclonedx::BomHelpers.purl` to avoid conflict in v2.0.0 (along with all other global methods)
56+
- Fixed existing usage via the built-in Nokogiri workaround of adding an underscore `purl_`
57+
- The XML tag is unchanged as `<purl>`
58+
5359
### Security
5460

5561
## [1.1.0] - 2019-07-13

cyclonedx-ruby.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
2525

2626
# Specify which files are part of the released package.
2727
spec.files = Dir[
28+
#
2829
# Executables and tasks
2930
"exe/*",
3031
"lib/**/*.rb",
32+
"lib/licenses.json",
3133
# Signatures
3234
"sig/**/*.rbs",
3335
]

exe/cyclonedx-ruby

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
require 'bom_builder'
5-
Bombuilder.build(ARGV[0])
4+
if ENV.fetch("MIMIC_NEXT_MAJOR_VERSION", "false").casecmp?("true")
5+
require 'cyclonedx/ruby'
6+
Cyclonedx::BomBuilder.build(ARGV[0])
7+
else
8+
require 'bom_builder'
9+
Bombuilder.build(ARGV[0])
10+
end

lib/cyclonedx/bom_builder.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
21
module Cyclonedx
32
class BomBuilder
43
SUPPORTED_BOM_FORMATS = %w[xml json]
54

5+
extend Cyclonedx::BomHelpers
6+
67
def self.build(path)
78
original_working_directory = Dir.pwd
89
setup(path)
@@ -71,7 +72,9 @@ def self.setup(path)
7172
end
7273

7374
@gems = []
74-
licenses_file = File.read "#{__dir__}/licenses.json"
75+
# Adjusted to point to lib/licenses.json relative to this file's directory (lib/cyclonedx)
76+
licenses_path = File.expand_path('../licenses.json', __dir__)
77+
licenses_file = File.read(licenses_path)
7578
@licenses_list = JSON.parse(licenses_file)
7679

7780
if @options[:path].nil?

lib/cyclonedx/bom_helpers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
module Cyclonedx
2828
module BomHelpers
29-
extend self
29+
module_function
3030

3131
def purl(name, version)
3232
"pkg:gem/#{name}@#{version}"
@@ -86,7 +86,11 @@ def build_bom_xml(gems)
8686
end
8787
end
8888
end
89-
xml.purl gem['purl']
89+
# The globally scoped legacy `Object#purl` method breaks the Nokogiri builder context
90+
# Fortunately Nokogiri has a built-in workaround, adding an underscore to the method name.
91+
# The resulting XML tag is still `<purl>`.
92+
# Globally scoped legacy `Object#purl` will be removed in v2.0.0, and this hack can be removed then.
93+
xml.purl_ gem['purl']
9094
end
9195
end
9296
end

lib/cyclonedx/ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
# This gem
1616
require_relative "ruby/version"
17-
require_relative "bom_builder"
18-
require_relative "bom_component"
1917
require_relative "bom_helpers"
18+
require_relative "bom_builder" # depends on bom_helpers
19+
require_relative "bom_component"
2020

2121
module Cyclonedx
2222
module Ruby

lib/cyclonedx_deprecated.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@
1515
deprecated_alias :instance, :build_json_bom, :build_json_bom, Cyclonedx::BomHelpers
1616
deprecated_alias :instance, :build_bom_xml, :build_bom_xml, Cyclonedx::BomHelpers
1717
deprecated_alias :instance, :get_gem, :get_gem, Cyclonedx::BomHelpers
18+
19+
# Sanity
20+
raise "Deprecated methods broken" unless purl('activesupport', '7.0.1') == "pkg:gem/[email protected]"

0 commit comments

Comments
 (0)