Store Livecheck#version as symbol or string
This commit is contained in:
parent
4b87da4da9
commit
0e8cebbb5b
@ -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.
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user