Initial small fixes
- Skip blank lines in watchlist - Initialize Livecheck#version as nil - Simplify livecheck_version logic - Make test a bit more understandable
This commit is contained in:
parent
bf03893227
commit
4b87da4da9
@ -67,7 +67,9 @@ module Homebrew
|
||||
args.named.to_formulae_and_casks
|
||||
elsif File.exist?(WATCHLIST_PATH)
|
||||
begin
|
||||
names = Pathname.new(WATCHLIST_PATH).read.lines.reject { |line| line.start_with?("#") }.map(&:strip)
|
||||
names = Pathname.new(WATCHLIST_PATH).read.lines
|
||||
.reject { |line| line.start_with?("#") || line.blank? }
|
||||
.map(&:strip)
|
||||
CLI::NamedArgs.new(*names).to_formulae_and_casks
|
||||
rescue Errno::ENOENT => e
|
||||
onoe e
|
||||
|
||||
@ -20,6 +20,7 @@ class Livecheck
|
||||
@skip_msg = nil
|
||||
@strategy = nil
|
||||
@url = nil
|
||||
@version = nil
|
||||
end
|
||||
|
||||
# Sets the `@regex` instance variable to the provided `Regexp` or returns the
|
||||
@ -88,10 +89,10 @@ class Livecheck
|
||||
@url = case val
|
||||
when nil
|
||||
return @url
|
||||
when :cask_url
|
||||
@formula_or_cask.url.to_s
|
||||
when :appcast
|
||||
@formula_or_cask.appcast.to_s
|
||||
when :cask_url
|
||||
@formula_or_cask.url.to_s
|
||||
when :head, :stable
|
||||
@formula_or_cask.send(val).url
|
||||
when :homepage
|
||||
|
||||
@ -115,9 +115,11 @@ module Homebrew
|
||||
# comparison.
|
||||
livecheck_version = formula_or_cask.livecheck.version
|
||||
current = if livecheck_version.is_a?(String)
|
||||
livecheck_version
|
||||
else
|
||||
version = if formula
|
||||
Version.new(livecheck_version)
|
||||
elsif livecheck_version.is_a?(Array)
|
||||
separator, method = livecheck_version
|
||||
Version.new(formula_or_cask.version.to_s.split(separator, 2).try(method))
|
||||
elsif formula
|
||||
if formula.head_only?
|
||||
formula.any_installed_version.version.commit
|
||||
else
|
||||
@ -125,13 +127,6 @@ module Homebrew
|
||||
end
|
||||
else
|
||||
Version.new(formula_or_cask.version)
|
||||
end
|
||||
if livecheck_version.is_a?(Array)
|
||||
separator, method = livecheck_version
|
||||
Version.new(version.to_s.split(separator, 2).try(method))
|
||||
else
|
||||
version
|
||||
end
|
||||
end
|
||||
|
||||
latest = if formula&.stable? || cask
|
||||
|
||||
@ -113,8 +113,8 @@ describe Livecheck do
|
||||
end
|
||||
|
||||
it "returns value if set" do
|
||||
livecheckable.version("foo")
|
||||
expect(livecheckable.version).to eq("foo")
|
||||
livecheckable.version("1.2.3")
|
||||
expect(livecheckable.version).to eq("1.2.3")
|
||||
|
||||
livecheckable.version(:before_comma)
|
||||
expect(livecheckable.version).to eq([",", :first])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user