Class: Csspin::PackageSpec
- Inherits:
-
Object
- Object
- Csspin::PackageSpec
- Defined in:
- lib/csspin/package_spec.rb
Instance Attribute Summary collapse
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#package_name ⇒ Object
readonly
Returns the value of attribute package_name.
Class Method Summary collapse
- .parse(raw) ⇒ Object
- .split_package_and_version(normalized) ⇒ Object
- .validate_unscoped_package!(normalized) ⇒ Object
Instance Method Summary collapse
-
#initialize(full_name:, package_name:) ⇒ PackageSpec
constructor
A new instance of PackageSpec.
Constructor Details
#initialize(full_name:, package_name:) ⇒ PackageSpec
Returns a new instance of PackageSpec.
42 43 44 45 |
# File 'lib/csspin/package_spec.rb', line 42 def initialize(full_name:, package_name:) @full_name = full_name @package_name = package_name end |
Instance Attribute Details
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
5 6 7 |
# File 'lib/csspin/package_spec.rb', line 5 def full_name @full_name end |
#package_name ⇒ Object (readonly)
Returns the value of attribute package_name.
5 6 7 |
# File 'lib/csspin/package_spec.rb', line 5 def package_name @package_name end |
Class Method Details
.parse(raw) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/csspin/package_spec.rb', line 7 def self.parse(raw) normalized = raw.to_s.strip raise ArgumentError, "package is required" if normalized.empty? package_part, = split_package_and_version(normalized) package_name = package_part.split("/").last new(full_name: normalized, package_name: package_name) end |
.split_package_and_version(normalized) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/csspin/package_spec.rb', line 17 def self.split_package_and_version(normalized) return validate_unscoped_package!(normalized) unless normalized.include?("@") if normalized.start_with?("@") scope, remainder = normalized.split("/", 2) raise ArgumentError, "invalid package format: #{normalized}" if scope.nil? || scope.length == 1 || scope.count("@") != 1 || remainder.nil? || remainder.empty? package, version = remainder.split("@", 2) raise ArgumentError, "invalid package format: #{normalized}" if package.nil? || package.empty? || package.include?("/") || version&.empty? || version&.include?("/") || version&.include?("@") ["#{scope}/#{package}", version] else package, version = normalized.split("@", 2) raise ArgumentError, "invalid package format: #{normalized}" if package.nil? || package.empty? || package.include?("/") || version&.empty? || version&.include?("/") || version&.include?("@") [package, version] end end |
.validate_unscoped_package!(normalized) ⇒ Object
36 37 38 39 40 |
# File 'lib/csspin/package_spec.rb', line 36 def self.validate_unscoped_package!(normalized) raise ArgumentError, "invalid package format: #{normalized}" if normalized.empty? || normalized.include?("/") [normalized, nil] end |