Store Livecheck#version as symbol or string

This commit is contained in:
Seeker 2020-09-03 20:26:13 -07:00 committed by Sam Ford
parent 4b87da4da9
commit 0e8cebbb5b
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
3 changed files with 7 additions and 15 deletions

View File

@ -106,22 +106,12 @@ class Livecheck
# TODO: documentation
def version(val = nil)
@version = case val
when nil
return @version
when :before_comma
[",", :first]
when :after_comma
[",", :second]
when :before_colon
[":", :first]
when :after_colon
[":", :second]
when String
val
else
return @version if val.nil?
unless val.is_a?(String) || (val.is_a?(Symbol) && Cask::DSL::Version.method_defined?(val))
raise TypeError, "Livecheck#version expects a String or valid Symbol"
end
@version = val
end
# Returns a `Hash` of all instance variable values.

View File

@ -125,6 +125,8 @@ module Homebrew
else
formula.stable.version
end
elsif livecheck_version.is_a?(Symbol)
Version.new(Cask::DSL::Version.new(formula_or_cask.version).try(livecheck_version))
else
Version.new(formula_or_cask.version)
end

View File

@ -117,7 +117,7 @@ describe Livecheck do
expect(livecheckable.version).to eq("1.2.3")
livecheckable.version(:before_comma)
expect(livecheckable.version).to eq([",", :first])
expect(livecheckable.version).to eq(:before_comma)
end
it "raises a TypeError if the argument isn't a String or Symbol" do