Class: Livecheck

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
livecheck.rb

Overview

The Livecheck class implements the DSL methods used in a formula’s, cask’s or resource’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(package_or_resource) ⇒ Livecheck

Returns a new instance of Livecheck.



20
21
22
23
24
25
26
27
28
29
# File 'livecheck.rb', line 20

def initialize(package_or_resource)
  @package_or_resource = package_or_resource
  @referenced_cask_name = nil
  @referenced_formula_name = nil
  @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/resource is skipped (e.g. No longer developed or maintained).

Returns:



18
19
20
# File 'livecheck.rb', line 18

def skip_msg
  @skip_msg
end

#strategy_blockObject (readonly)

Returns the value of attribute strategy_block.



126
127
128
# File 'livecheck.rb', line 126

def strategy_block
  @strategy_block
end

Instance Method Details

#cask(cask_name = nil) ⇒ String?

Sets the @referenced_cask_name instance variable to the provided String or returns the @referenced_cask_name instance variable when no argument is provided. Inherited livecheck values from the referenced cask (e.g. regex) can be overridden in the livecheck block.

Parameters:

  • cask_name (String) (defaults to: nil)

    name of cask to inherit livecheck info from

Returns:



38
39
40
41
42
43
44
45
46
47
# File 'livecheck.rb', line 38

def cask(cask_name = nil)
  case cask_name
  when nil
    @referenced_cask_name
  when String
    @referenced_cask_name = cask_name
  else
    raise TypeError, "Livecheck#cask expects a String"
  end
end

#formula(formula_name = nil) ⇒ String?

Sets the @referenced_formula_name instance variable to the provided String or returns the @referenced_formula_name instance variable when no argument is provided. Inherited livecheck values from the referenced formula (e.g. regex) can be overridden in the livecheck block.

Parameters:

  • formula_name (String) (defaults to: nil)

    name of formula to inherit livecheck info from

Returns:



56
57
58
59
60
61
62
63
64
65
# File 'livecheck.rb', line 56

def formula(formula_name = nil)
  case formula_name
  when nil
    @referenced_formula_name
  when String
    @referenced_formula_name = formula_name
  else
    raise TypeError, "Livecheck#formula expects a String"
  end
end

#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)


72
73
74
75
76
77
78
79
80
81
# File 'livecheck.rb', line 72

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/resource 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)


91
92
93
94
95
96
97
98
99
# File 'livecheck.rb', line 91

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

Returns:

  • (Boolean)


102
103
104
# File 'livecheck.rb', line 102

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:



113
114
115
116
117
118
119
120
121
122
123
124
# File 'livecheck.rb', line 113

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)


151
152
153
154
155
156
157
158
159
160
161
# File 'livecheck.rb', line 151

def to_hash
  {
    "cask"     => @referenced_cask_name,
    "formula"  => @referenced_formula_name,
    "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/resource (e.g. :stable, :homepage, :head, :url).

Parameters:

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

    URL to check for version information

Returns:



134
135
136
137
138
139
140
141
142
143
# File 'livecheck.rb', line 134

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