Extended the livecheck DSL to work for resources

This commit is contained in:
Mohammad Zain Abbas 2022-06-30 16:08:13 +02:00
parent ff63136c6f
commit 1ba610707d

View File

@ -5,6 +5,7 @@ require "download_strategy"
require "checksum" require "checksum"
require "version" require "version"
require "mktemp" require "mktemp"
require "livecheck"
require "extend/on_os" require "extend/on_os"
# Resource is the fundamental representation of an external resource. The # Resource is the fundamental representation of an external resource. The
@ -36,6 +37,8 @@ class Resource
@checksum = nil @checksum = nil
@using = nil @using = nil
@patches = [] @patches = []
@livecheck = nil
@livecheckable = false
instance_eval(&block) if block instance_eval(&block) if block
end end
@ -168,6 +171,32 @@ class Resource
EOS EOS
end end
# @!attribute [w] livecheck
# {Livecheck} can be used to check for newer versions of the software.
# This method evaluates the DSL specified in the livecheck block of the
# {Resource} (if it exists) and sets the instance variables of a {Livecheck}
# object accordingly. This is used by `brew livecheck` to check for newer
# versions of the software.
#
# <pre>livecheck do
# url "https://example.com/foo/releases"
# regex /foo-(\d+(?:\.\d+)+)\.tar/
# end</pre>
def livecheck(&block)
@livecheck ||= Livecheck.new(self)
return @livecheck unless block
@livecheckable = true
@livecheck.instance_eval(&block)
end
# Whether a livecheck specification is defined or not.
# It returns true when a livecheck block is present in the {Resource} and
# false otherwise, and is used by livecheck.
def livecheckable?
@livecheckable == true
end
def sha256(val) def sha256(val)
@checksum = Checksum.new(val) @checksum = Checksum.new(val)
end end