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

View File

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

View File

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