Module: Homebrew::Livecheck::Strategy Private

Defined in:
brew/Library/Homebrew/livecheck/strategy.rb,
brew/Library/Homebrew/livecheck/strategy/git.rb,
brew/Library/Homebrew/livecheck/strategy/gnu.rb,
brew/Library/Homebrew/livecheck/strategy/npm.rb,
brew/Library/Homebrew/livecheck/strategy/pypi.rb,
brew/Library/Homebrew/livecheck/strategy/xorg.rb,
brew/Library/Homebrew/livecheck/strategy/gnome.rb,
brew/Library/Homebrew/livecheck/strategy/apache.rb,
brew/Library/Homebrew/livecheck/strategy/hackage.rb,
brew/Library/Homebrew/livecheck/strategy/bitbucket.rb,
brew/Library/Homebrew/livecheck/strategy/launchpad.rb,
brew/Library/Homebrew/livecheck/strategy/page_match.rb,
brew/Library/Homebrew/livecheck/strategy/sourceforge.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

The Livecheck::Strategy module contains the various strategies as well as some general-purpose methods for working with them. Within the context of the brew livecheck command, strategies are established procedures for finding new software versions at a given source.

Defined Under Namespace

Classes: Apache, Bitbucket, Git, Gnome, Gnu, Hackage, Launchpad, Npm, PageMatch, Pypi, Sourceforge, Xorg

Class Method Summary collapse

Class Method Details

.from_symbol(symbol) ⇒ Strategy?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the Strategy that corresponds to the provided Symbol (or nil if there is no matching Strategy).

Parameters:

  • symbol (Symbol)

    the strategy name in snake case as a Symbol (e.g., :page_match)

Returns:



46
47
48
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 46

def from_symbol(symbol)
  strategies[symbol]
end

.from_url(url, regex_provided = nil) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an array of strategies that apply to the provided URL.

Parameters:

  • url (String)

    the URL to check for matching strategies

  • regex_provided (Boolean) (defaults to: nil)

    whether a regex is provided in a livecheck block

Returns:

  • (Array)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'brew/Library/Homebrew/livecheck/strategy.rb', line 55

def from_url(url, regex_provided = nil)
  usable_strategies = strategies.values.select do |strategy|
    # Ignore strategies with a priority of 0 or lower
    next if strategy.const_defined?(:PRIORITY) && !strategy::PRIORITY.positive?

    strategy.respond_to?(:match?) && strategy.match?(url)
  end

  usable_strategies << strategies[:page_match] if strategies.key?(:page_match) && regex_provided

  # Sort usable strategies in descending order by priority, using the
  # DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant
  usable_strategies.sort_by do |strategy|
    (strategy.const_defined?(:PRIORITY) ? -strategy::PRIORITY : -DEFAULT_PRIORITY)
  end
end