Module: Purl
- Defined in:
- lib/purl.rb,
lib/purl/errors.rb,
lib/purl/version.rb,
lib/purl/package_url.rb,
lib/purl/registry_url.rb
Defined Under Namespace
Classes: Error, InvalidNameError, InvalidNamespaceError, InvalidQualifierError, InvalidSchemeError, InvalidSubpathError, InvalidTypeError, InvalidVersionError, MalformedUrlError, MissingRegistryInfoError, PackageURL, ParseError, RegistryError, RegistryURL, UnsupportedTypeError, ValidationError
Constant Summary collapse
- KNOWN_TYPES =
Known PURL types loaded from JSON configuration
load_types_config["types"].keys.sort.freeze
- InvalidPackageURL =
Legacy compatibility - matches packageurl-ruby’s exception name
ParseError
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.all_type_info ⇒ Object
Get comprehensive information about all types.
-
.default_registry(type) ⇒ Object
Get default registry URL for a type.
-
.from_registry_url(registry_url, type: nil) ⇒ Object
Convenience method for parsing registry URLs back to PURLs.
-
.known_type?(type) ⇒ Boolean
Check if a type is known/valid.
-
.known_types ⇒ Object
Returns all known PURL types.
-
.load_types_config ⇒ Object
Load PURL types configuration from JSON file.
-
.parse(purl_string) ⇒ Object
Convenience method for parsing PURL strings.
-
.registry_config(type) ⇒ Object
Get registry configuration for a type.
-
.registry_supported_types ⇒ Object
Returns types that have registry URL support.
-
.reverse_parsing_supported_types ⇒ Object
Returns types that support reverse parsing from registry URLs.
-
.type_config(type) ⇒ Object
Get type configuration from JSON.
-
.type_description(type) ⇒ Object
Get description for a type.
-
.type_examples(type) ⇒ Object
Get examples for a type.
-
.type_info(type) ⇒ Object
Get type information including registry support.
-
.types_config_metadata ⇒ Object
Get metadata about the types configuration.
Class Method Details
.all_type_info ⇒ Object
Get comprehensive information about all types
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/purl.rb', line 71 def self.all_type_info result = {} # Start with known types KNOWN_TYPES.each do |type| result[type] = type_info(type) end # Add any registry-supported types not in known list RegistryURL.supported_types.each do |type| unless result.key?(type) result[type] = type_info(type) end end result end |
.default_registry(type) ⇒ Object
Get default registry URL for a type
120 121 122 123 124 125 |
# File 'lib/purl.rb', line 120 def self.default_registry(type) config = type_config(type) return nil unless config config["default_registry"] end |
.from_registry_url(registry_url, type: nil) ⇒ Object
Convenience method for parsing registry URLs back to PURLs
31 32 33 |
# File 'lib/purl.rb', line 31 def self.from_registry_url(registry_url, type: nil) RegistryURL.from_url(registry_url, type: type) end |
.known_type?(type) ⇒ Boolean
Check if a type is known/valid
51 52 53 |
# File 'lib/purl.rb', line 51 def self.known_type?(type) KNOWN_TYPES.include?(type.to_s.downcase) end |
.known_types ⇒ Object
Returns all known PURL types
36 37 38 |
# File 'lib/purl.rb', line 36 def self.known_types KNOWN_TYPES.dup end |
.load_types_config ⇒ Object
Load PURL types configuration from JSON file
12 13 14 15 16 17 18 |
# File 'lib/purl.rb', line 12 def self.load_types_config @types_config ||= begin config_path = File.join(__dir__, "..", "purl-types.json") require "json" JSON.parse(File.read(config_path)) end end |
.parse(purl_string) ⇒ Object
Convenience method for parsing PURL strings
24 25 26 |
# File 'lib/purl.rb', line 24 def self.parse(purl_string) PackageURL.parse(purl_string) end |
.registry_config(type) ⇒ Object
Get registry configuration for a type
112 113 114 115 116 117 |
# File 'lib/purl.rb', line 112 def self.registry_config(type) config = type_config(type) return nil unless config config["registry_config"] end |
.registry_supported_types ⇒ Object
Returns types that have registry URL support
41 42 43 |
# File 'lib/purl.rb', line 41 def self.registry_supported_types RegistryURL.supported_types end |
.reverse_parsing_supported_types ⇒ Object
Returns types that support reverse parsing from registry URLs
46 47 48 |
# File 'lib/purl.rb', line 46 def self.reverse_parsing_supported_types RegistryURL.supported_reverse_types end |
.type_config(type) ⇒ Object
Get type configuration from JSON
90 91 92 93 94 95 |
# File 'lib/purl.rb', line 90 def self.type_config(type) config = load_types_config["types"][type.to_s.downcase] return nil unless config config.dup # Return a copy to prevent modification end |
.type_description(type) ⇒ Object
Get description for a type
98 99 100 101 |
# File 'lib/purl.rb', line 98 def self.type_description(type) config = type_config(type) config ? config["description"] : nil end |
.type_examples(type) ⇒ Object
Get examples for a type
104 105 106 107 108 109 |
# File 'lib/purl.rb', line 104 def self.type_examples(type) config = type_config(type) return [] unless config config["examples"] || [] end |
.type_info(type) ⇒ Object
Get type information including registry support
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/purl.rb', line 56 def self.type_info(type) normalized_type = type.to_s.downcase { type: normalized_type, known: known_type?(normalized_type), description: type_description(normalized_type), default_registry: default_registry(normalized_type), examples: type_examples(normalized_type), registry_url_generation: RegistryURL.supports?(normalized_type), reverse_parsing: RegistryURL.supported_reverse_types.include?(normalized_type), route_patterns: RegistryURL.route_patterns_for(normalized_type) } end |
.types_config_metadata ⇒ Object
Get metadata about the types configuration
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/purl.rb', line 128 def self. config = load_types_config { version: config["version"], description: config["description"], source: config["source"], last_updated: config["last_updated"], total_types: config["types"].keys.length, registry_supported_types: config["types"].select { |_, v| v["registry_config"] }.keys.length, types_with_default_registry: config["types"].select { |_, v| v["default_registry"] }.keys.length } end |