class GitCompound::Repository::RemoteFile::GithubStrategy

Git archive strategy

Constants

GITHUB_PATTERN
GITHUB_URI

Public Class Methods

new(source, ref, file) click to toggle source
Calls superclass method
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 13
def initialize(source, ref, file)
  super
  @uri = github_uri
end

Public Instance Methods

contents() click to toggle source
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 18
def contents
  raise FileUnreachableError unless reachable?
  raise FileNotFoundError unless exists?
  @response.body
end
exists?() click to toggle source
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 28
def exists?
  @response ||= http_response(@uri)
  @response.code == 200.to_s
end
reachable?() click to toggle source
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 24
def reachable?
  @source.match(/#{GITHUB_PATTERN}/) ? true : false
end

Private Instance Methods

github_uri() click to toggle source
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 35
def github_uri
  github_location = @source.sub(/^#{GITHUB_PATTERN}/, '')
  github_location.gsub!(%r{^/|/$}, '')
  file_uri = "#{GITHUB_URI}/#{github_location}/#{@ref}/#{@file}"
  URI.parse(file_uri)
end
http_response(uri) click to toggle source
# File lib/git_compound/repository/remote_file/github_strategy.rb, line 42
def http_response(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.open_timeout = 4
  http.read_timeout = 4
  params = { 'User-Agent' => 'git_compound' }
  req = Net::HTTP::Get.new(uri.request_uri, params)
  http.request(req)
end