Class: OpsWalrus::DynamicPackageReference

Inherits:
PackageReference show all
Defined in:
lib/opswalrus/package_file.rb

Overview

these are dynamic package references defined at runtime when an OpsFile’s imports are being evaluated. this will usually be the case when an ops file does not belong to a package

Instance Attribute Summary

Attributes inherited from PackageReference

#local_name, #package_uri, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PackageReference

#initialize, #summary, #to_s

Constructor Details

This class inherits a constructor from OpsWalrus::PackageReference

Class Method Details

.import_resolution_dirname(package_uri, version) ⇒ Object



47
48
49
50
51
# File 'lib/opswalrus/package_file.rb', line 47

def self.import_resolution_dirname(package_uri, version)
  sanitized_package_uri = sanitize_path(package_uri || raise(Error, "Unspecified package reference"))
  sanitized_version = sanitize_path(version || "")
  "pkg_#{sanitized_package_uri}_version_#{sanitized_version}"
end

.sanitize_path(path) ⇒ Object



52
53
54
55
# File 'lib/opswalrus/package_file.rb', line 52

def self.sanitize_path(path)
  # found this at https://apidock.com/rails/v5.2.3/ActiveStorage/Filename/sanitized
  path.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
end

Instance Method Details

#import_resolution_dirnameObject



56
57
58
# File 'lib/opswalrus/package_file.rb', line 56

def import_resolution_dirname
  DynamicPackageReference.import_resolution_dirname(@package_uri, @version)
end