Class: Livecheck
- Inherits:
-
Object
- Object
- Livecheck
- Defined in:
- Library/Homebrew/livecheck.rb
Overview
The Livecheck class implements the DSL methods used in a formula's
livecheck
block and stores related instance variables. Most of these methods
also return the related instance variable when no argument is provided.
This information is used by the brew livecheck
command to control its
behavior.
Instance Attribute Summary collapse
-
#skip_msg ⇒ String?
readonly
A very brief description of why the formula is skipped (e.g.
No longer developed or maintained
).
Instance Method Summary collapse
-
#initialize(formula) ⇒ Livecheck
constructor
A new instance of Livecheck.
-
#regex(pattern = nil) ⇒ Regexp?
Sets the
@regex
instance variable to the providedRegexp
or returns the@regex
instance variable when no argument is provided. -
#skip(skip_msg = nil) ⇒ Boolean
Sets the
@skip
instance variable totrue
and sets the@skip_msg
instance variable if aString
is provided. -
#skip? ⇒ Boolean
Should
livecheck
skip this formula?. -
#strategy(symbol = nil) ⇒ Symbol?
Sets the
@strategy
instance variable to the providedSymbol
or returns the@strategy
instance variable when no argument is provided. -
#to_hash ⇒ Hash
Returns a
Hash
of all instance variable values. -
#url(val = nil) ⇒ String?
Sets the
@url
instance variable to the provided argument or returns the@url
instance variable when no argument is provided.
Constructor Details
#initialize(formula) ⇒ Livecheck
Returns a new instance of Livecheck.
16 17 18 19 20 21 22 23 |
# File 'Library/Homebrew/livecheck.rb', line 16 def initialize(formula) @formula = formula @regex = nil @skip = false @skip_msg = nil @strategy = nil @url = nil end |
Instance Attribute Details
#skip_msg ⇒ String? (readonly)
A very brief description of why the formula is skipped (e.g. No longer
developed or maintained
).
14 15 16 |
# File 'Library/Homebrew/livecheck.rb', line 14 def skip_msg @skip_msg end |
Instance Method Details
#regex(pattern = nil) ⇒ Regexp?
Sets the @regex
instance variable to the provided Regexp
or returns the
@regex
instance variable when no argument is provided.
30 31 32 33 34 35 36 37 38 39 |
# File 'Library/Homebrew/livecheck.rb', line 30 def regex(pattern = nil) case pattern when nil @regex when Regexp @regex = pattern else raise TypeError, "Livecheck#regex expects a Regexp" end end |
#skip(skip_msg = nil) ⇒ Boolean
Sets the @skip
instance variable to true
and sets the @skip_msg
instance variable if a String
is provided. @skip
is used to indicate
that the formula should be skipped and the skip_msg
very briefly describes
why the formula is skipped (e.g. "No longer developed or maintained").
48 49 50 51 52 53 54 55 56 |
# File 'Library/Homebrew/livecheck.rb', line 48 def skip(skip_msg = nil) if skip_msg.is_a?(String) @skip_msg = skip_msg elsif skip_msg.present? raise TypeError, "Livecheck#skip expects a String" end @skip = true end |
#skip? ⇒ Boolean
Should livecheck
skip this formula?
59 60 61 |
# File 'Library/Homebrew/livecheck.rb', line 59 def skip? @skip end |
#strategy(symbol = nil) ⇒ Symbol?
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.
70 71 72 73 74 75 76 77 78 79 |
# File 'Library/Homebrew/livecheck.rb', line 70 def strategy(symbol = nil) case symbol when nil @strategy when Symbol @strategy = symbol else raise TypeError, "Livecheck#strategy expects a Symbol" end end |
#to_hash ⇒ Hash
Returns a Hash
of all instance variable values.
105 106 107 108 109 110 111 112 113 |
# File 'Library/Homebrew/livecheck.rb', line 105 def to_hash { "regex" => @regex, "skip" => @skip, "skip_msg" => @skip_msg, "strategy" => @strategy, "url" => @url, } end |
#url(val = nil) ⇒ String?
Sets the @url
instance variable to the provided argument or returns the
@url
instance variable when no argument is provided. The argument can be
a String
(a URL) or a supported Symbol
corresponding to a URL in the
formula (e.g. :stable
, :homepage
, or :head
).
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'Library/Homebrew/livecheck.rb', line 88 def url(val = nil) @url = case val when nil return @url when :head, :stable @formula.send(val).url when :homepage @formula.homepage when String val else raise TypeError, "Livecheck#url expects a String or valid Symbol" end end |