2020-03-16 01:37:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Livecheck can be used to check for newer versions of the software.
|
|
|
|
# The livecheck DSL specified in the formula is evaluated the methods
|
|
|
|
# of this class, which set the instance variables accordingly. The
|
|
|
|
# information is used by brew livecheck when checking for newer versions
|
|
|
|
# of the software.
|
|
|
|
class Livecheck
|
|
|
|
# The reason for skipping livecheck for the formula.
|
|
|
|
# e.g. `Not maintained`
|
|
|
|
attr_reader :skip_msg
|
|
|
|
|
2020-05-31 00:10:46 +05:30
|
|
|
def initialize(formula)
|
|
|
|
@formula = formula
|
2020-03-16 01:37:49 +05:30
|
|
|
@regex = nil
|
|
|
|
@skip = false
|
|
|
|
@skip_msg = nil
|
2020-08-05 11:54:37 -04:00
|
|
|
@strategy = nil
|
2020-03-16 01:37:49 +05:30
|
|
|
@url = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the regex instance variable to the argument given, returns the
|
|
|
|
# regex instance variable when no argument is given.
|
|
|
|
def regex(pattern = nil)
|
2020-08-07 17:25:08 -04:00
|
|
|
case pattern
|
|
|
|
when nil
|
|
|
|
@regex
|
|
|
|
when Regexp
|
|
|
|
@regex = pattern
|
|
|
|
else
|
|
|
|
raise TypeError, "Livecheck#regex expects a Regexp"
|
|
|
|
end
|
2020-03-16 01:37:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the skip instance variable to true, indicating that livecheck
|
|
|
|
# must be skipped for the formula. If an argument is given and present,
|
|
|
|
# its value is assigned to the skip_msg instance variable, else nil is
|
|
|
|
# assigned.
|
|
|
|
def skip(skip_msg = nil)
|
2020-08-07 17:25:08 -04:00
|
|
|
if skip_msg.is_a?(String)
|
|
|
|
@skip_msg = skip_msg
|
|
|
|
elsif skip_msg.present?
|
|
|
|
raise TypeError, "Livecheck#skip expects a String"
|
|
|
|
end
|
|
|
|
|
2020-03-16 01:37:49 +05:30
|
|
|
@skip = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Should livecheck be skipped for the formula?
|
|
|
|
def skip?
|
|
|
|
@skip
|
|
|
|
end
|
|
|
|
|
2020-08-05 11:54:37 -04:00
|
|
|
# Sets the strategy instance variable to the provided symbol or returns the
|
|
|
|
# strategy instance variable when no argument is provided. The strategy
|
|
|
|
# symbols use snake case (e.g., `:page_match`) and correspond to the strategy
|
|
|
|
# file name.
|
|
|
|
# @param symbol [Symbol] symbol for the desired strategy
|
|
|
|
def strategy(symbol = nil)
|
|
|
|
case symbol
|
|
|
|
when nil
|
|
|
|
@strategy
|
|
|
|
when Symbol
|
|
|
|
@strategy = symbol
|
|
|
|
else
|
|
|
|
raise TypeError, "Livecheck#strategy expects a Symbol"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-16 01:37:49 +05:30
|
|
|
# Sets the url instance variable to the argument given, returns the url
|
|
|
|
# instance variable when no argument is given.
|
|
|
|
def url(val = nil)
|
2020-05-31 00:10:46 +05:30
|
|
|
@url = case val
|
2020-08-07 17:25:08 -04:00
|
|
|
when nil
|
|
|
|
return @url
|
2020-05-31 00:10:46 +05:30
|
|
|
when :head, :stable, :devel
|
|
|
|
@formula.send(val).url
|
|
|
|
when :homepage
|
|
|
|
@formula.homepage
|
2020-08-07 17:25:08 -04:00
|
|
|
when String
|
2020-05-31 00:10:46 +05:30
|
|
|
val
|
2020-08-07 17:25:08 -04:00
|
|
|
else
|
|
|
|
raise TypeError, "Livecheck#url expects a String or valid Symbol"
|
2020-05-31 00:10:46 +05:30
|
|
|
end
|
2020-03-16 01:37:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a Hash of all instance variable values.
|
|
|
|
def to_hash
|
|
|
|
{
|
|
|
|
"regex" => @regex,
|
|
|
|
"skip" => @skip,
|
|
|
|
"skip_msg" => @skip_msg,
|
2020-08-05 11:54:37 -04:00
|
|
|
"strategy" => @strategy,
|
2020-03-16 01:37:49 +05:30
|
|
|
"url" => @url,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|