diff --git a/Library/Homebrew/cask/dsl/version.rb b/Library/Homebrew/cask/dsl/version.rb index eb1ea6fe04..cc20fb429d 100644 --- a/Library/Homebrew/cask/dsl/version.rb +++ b/Library/Homebrew/cask/dsl/version.rb @@ -132,6 +132,12 @@ module Cask version { [minor, patch].reject(&:empty?).join(".") } end + # @api public + sig { returns(T::Array[Version]) } # Only top-level T.self_type is supported https://sorbet.org/docs/self-type + def csv + split(",").map(&self.class.method(:new)) + end + # @api public sig { returns(T.self_type) } def before_comma @@ -147,12 +153,14 @@ module Cask # @api public sig { returns(T.self_type) } def before_colon + # odeprecated "Cask::DSL::Version#before_colon", "Cask::DSL::Version#csv" version { split(":", 2).first } end # @api public sig { returns(T.self_type) } def after_colon + # odeprecated "Cask::DSL::Version#after_colon", "Cask::DSL::Version#csv" version { split(":", 2).second } end diff --git a/Library/Homebrew/test/cask/dsl/version_spec.rb b/Library/Homebrew/test/cask/dsl/version_spec.rb index a8164b30f5..d2b46c47ad 100644 --- a/Library/Homebrew/test/cask/dsl/version_spec.rb +++ b/Library/Homebrew/test/cask/dsl/version_spec.rb @@ -140,6 +140,20 @@ describe Cask::DSL::Version, :cask do "1.2.3-4,5:6" => "2.3-4" end + describe "#csv" do + subject { version.csv } + + include_examples "expectations hash", :raw_version, + :latest => ["latest"], + "latest" => ["latest"], + "" => [], + nil => [], + "1.2.3" => ["1.2.3"], + "1.2.3," => ["1.2.3"], + ",abc" => ["", "abc"], + "1.2.3,abc" => ["1.2.3", "abc"] + end + describe "#before_comma" do include_examples "version expectations hash", :before_comma, "1.2.3" => "1.2.3", diff --git a/docs/Cask-Cookbook.md b/docs/Cask-Cookbook.md index 30a2824025..19b66676fe 100644 --- a/docs/Cask-Cookbook.md +++ b/docs/Cask-Cookbook.md @@ -1268,7 +1268,7 @@ The examples above can become hard to read, however. Since many of these changes Similar to `dots_to_hyphens`, we provide all logical permutations of `{dots,hyphens,underscores}_to_{dots,hyphens,underscores}`. The same applies to `no_dots` in the form of `no_{dots,hyphens,underscores}`, with an extra `no_dividers` that applies all of those at once. -Finally, there are `before_colon` and `after_colon` that act like their `comma` counterparts. These four are extra special to allow for otherwise complex cases, and should be used sparingly. There should be no more than one of `,` and `:` per `version`. Use `,` first, and `:` only if absolutely necessary. +Finally, there is `csv` that returns an array of comma-separated values. `csv`, `before_comma` and `after_comma` are extra special to allow for otherwise complex cases, and should be used sparingly. There should be no more than two of `,` per `version`. ### Stanza: `zap`