cask: add #csv to version DSL
This commit is contained in:
parent
d63c4d2761
commit
68160df041
@ -132,6 +132,12 @@ module Cask
|
|||||||
version { [minor, patch].reject(&:empty?).join(".") }
|
version { [minor, patch].reject(&:empty?).join(".") }
|
||||||
end
|
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
|
# @api public
|
||||||
sig { returns(T.self_type) }
|
sig { returns(T.self_type) }
|
||||||
def before_comma
|
def before_comma
|
||||||
@ -147,12 +153,14 @@ module Cask
|
|||||||
# @api public
|
# @api public
|
||||||
sig { returns(T.self_type) }
|
sig { returns(T.self_type) }
|
||||||
def before_colon
|
def before_colon
|
||||||
|
# odeprecated "Cask::DSL::Version#before_colon", "Cask::DSL::Version#csv"
|
||||||
version { split(":", 2).first }
|
version { split(":", 2).first }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
sig { returns(T.self_type) }
|
sig { returns(T.self_type) }
|
||||||
def after_colon
|
def after_colon
|
||||||
|
# odeprecated "Cask::DSL::Version#after_colon", "Cask::DSL::Version#csv"
|
||||||
version { split(":", 2).second }
|
version { split(":", 2).second }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -140,6 +140,20 @@ describe Cask::DSL::Version, :cask do
|
|||||||
"1.2.3-4,5:6" => "2.3-4"
|
"1.2.3-4,5:6" => "2.3-4"
|
||||||
end
|
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
|
describe "#before_comma" do
|
||||||
include_examples "version expectations hash", :before_comma,
|
include_examples "version expectations hash", :before_comma,
|
||||||
"1.2.3" => "1.2.3",
|
"1.2.3" => "1.2.3",
|
||||||
|
|||||||
@ -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.
|
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`
|
### Stanza: `zap`
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user