cask: add #csv to version DSL

This commit is contained in:
fn ⌃ ⌥ 2021-11-16 12:49:51 -08:00
parent d63c4d2761
commit 68160df041
3 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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",

View File

@ -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`