Class: Homebrew::Livecheck::Strategy::Launchpad

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/livecheck/strategy/launchpad.rb

Overview

The Launchpad strategy identifies versions of software at launchpad.net by checking the main page for a project.

Launchpad URLs take a variety of formats but all the current formats contain the project name as the first part of the URL path: * https://launchpad.net/example/1.2/1.2.3/+download/example-1.2.3.tar.gz * https://launchpad.net/example/trunk/1.2.3/+download/example-1.2.3.tar.gz * https://code.launchpad.net/example/1.2/1.2.3/+download/example-1.2.3.tar.gz

The default regex identifies the latest version within an HTML element found on the main page for a project: ```html

Latest version is 1.2.3

```

Constant Summary collapse

URL_MATCH_REGEX =

The Regexp used to determine if the strategy applies to the URL.

/launchpad\.net/i.freeze

Class Method Summary collapse

Class Method Details

.find_versions(url, regex = nil) ⇒ Hash

Generates a URL and regex (if one isn’t provided) and passes them to the PageMatch#find_versions method to identify versions in the content.

Parameters:

  • url (String)

    the URL of the content to check

  • regex (Regexp) (defaults to: nil)

    a regex used for matching versions in content

Returns:

  • (Hash)


41
42
43
44
45
46
47
48
49
50
51
# File 'brew/Library/Homebrew/livecheck/strategy/launchpad.rb', line 41

def self.find_versions(url, regex = nil)
  %r{launchpad\.net/(?<project_name>[^/]+)}i =~ url

  # The main page for the project on Launchpad
  page_url = "https://launchpad.net/#{project_name}"

  # The default regex is the same for all URLs using this strategy
  regex ||= %r{class="[^"]*version[^"]*"[^>]*>\s*Latest version is (.+)\s*</}

  Homebrew::Livecheck::Strategy::PageMatch.find_versions(page_url, regex)
end

.match?(url) ⇒ Boolean

Whether the strategy can be applied to the provided URL.

Parameters:

  • url (String)

    the URL to match against

Returns:

  • (Boolean)


31
32
33
# File 'brew/Library/Homebrew/livecheck/strategy/launchpad.rb', line 31

def self.match?(url)
  URL_MATCH_REGEX.match?(url)
end