Class: Livecheck

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
brew/Library/Homebrew/livecheck.rb

Overview

The Livecheck class implements the DSL methods used in a formula’s or cask’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. Example livecheck blocks can be found in the brew livecheck documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula_or_cask) ⇒ Livecheck

Returns a new instance of Livecheck.



19
20
21
22
23
24
25
26
# File 'brew/Library/Homebrew/livecheck.rb', line 19

def initialize(formula_or_cask)
  @formula_or_cask = formula_or_cask
  @regex = nil
  @skip = false
  @skip_msg = nil
  @strategy = nil
  @url = nil
end

Instance Attribute Details

#skip_msgString? (readonly)

A very brief description of why the formula/cask is skipped (e.g. No longer developed or maintained).

Returns:



17
18
19
# File 'brew/Library/Homebrew/livecheck.rb', line 17

def skip_msg
  @skip_msg
end

#strategy_blockObject (readonly)

Returns the value of attribute strategy_block.



86
87
88
# File 'brew/Library/Homebrew/livecheck.rb', line 86

def strategy_block
  @strategy_block
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.

Parameters:

  • pattern (Regexp) (defaults to: nil)

    regex to use for matching versions in content

Returns:

  • (Regexp, nil)


33
34
35
36
37
38
39
40
41
42
# File 'brew/Library/Homebrew/livecheck.rb', line 33

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/cask should be skipped and the skip_msg very briefly describes why it is skipped (e.g. “No longer developed or maintained”).

Parameters:

  • skip_msg (String) (defaults to: nil)

    string describing why the formula/cask is skipped

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
# File 'brew/Library/Homebrew/livecheck.rb', line 51

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/cask?

Returns:

  • (Boolean)


62
63
64
# File 'brew/Library/Homebrew/livecheck.rb', line 62

def skip?
  @skip
end

#strategy(symbol = nil, &block) ⇒ 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.

Parameters:

  • symbol (Symbol) (defaults to: nil)

    symbol for the desired strategy

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'brew/Library/Homebrew/livecheck.rb', line 73

def strategy(symbol = nil, &block)
  @strategy_block = block if block

  case symbol
  when nil
    @strategy
  when Symbol
    @strategy = symbol
  else
    raise TypeError, "Livecheck#strategy expects a Symbol"
  end
end

#to_hashHash

Returns a Hash of all instance variable values.

Returns:

  • (Hash)


110
111
112
113
114
115
116
117
118
# File 'brew/Library/Homebrew/livecheck.rb', line 110

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/cask (e.g. :stable, :homepage, :head, :url).

Parameters:

  • val (String, Symbol) (defaults to: nil)

    URL to check for version information

Returns:



94
95
96
97
98
99
100
101
102
103
# File 'brew/Library/Homebrew/livecheck.rb', line 94

def url(val = nil)
  case val
  when nil
    @url
  when String, :head, :homepage, :stable, :url
    @url = val
  else
    raise TypeError, "Livecheck#url expects a String or valid Symbol"
  end
end