Class: RepositoryLink

Inherits:
Object
  • Object
show all
Defined in:
lib/spm_version_updates/repository_link.rb

Overview

Parses supported git remote URLs and renders host-specific links.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository_url) ⇒ RepositoryLink

Returns a new instance of RepositoryLink.



39
40
41
42
43
44
45
# File 'lib/spm_version_updates/repository_link.rb', line 39

def initialize(repository_url)
  @value = repository_url.to_s.strip
  @host = nil
  @raw_path = nil
  @path = nil
  configure_remote(remote_match)
end

Class Method Details

.from(repository_url) ⇒ Object



34
35
36
37
# File 'lib/spm_version_updates/repository_link.rb', line 34

def self.from(repository_url)
  link = new(repository_url)
  link if link.valid?
end

Instance Method Details

#compare_url(current, available) ⇒ Object



51
52
53
54
55
# File 'lib/spm_version_updates/repository_link.rb', line 51

def compare_url(current, available)
  current_ref = URI.encode_www_form_component(current.to_s)
  available_ref = URI.encode_www_form_component(available.to_s)
  "#{base_url}#{link_builder.fetch(:compare).call(current_ref, available_ref)}"
end


62
63
64
65
66
67
68
# File 'lib/spm_version_updates/repository_link.rb', line 62

def markdown_links(updates, separator: "<br>")
  compare_links = updates.map.with_index(1) { |update, index|
    label = updates.size == 1 ? "Compare" : "Compare #{index}"
    "[#{label}](#{compare_url(update[:current], update[:available])})"
  }
  (compare_links + [release_link]).join(separator)
end


57
58
59
60
# File 'lib/spm_version_updates/repository_link.rb', line 57

def release_link
  label, path = link_builder.fetch(:release)
  "[#{label}](#{base_url}#{path})"
end

#valid?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/spm_version_updates/repository_link.rb', line 47

def valid?
  @host && @path
end