Class: GitCompound::Repository::RemoteFile::GithubStrategy

Inherits:
RemoteFileStrategy show all
Defined in:
lib/git_compound/repository/remote_file/github_strategy.rb

Overview

Git archive strategy

Constant Summary collapse

GITHUB_URI =
'https://raw.githubusercontent.com'
GITHUB_PATTERN =
'[email protected]:|https:\/\/github.com'

Instance Method Summary collapse

Constructor Details

#initialize(source, ref, file) ⇒ GithubStrategy

Returns a new instance of GithubStrategy.



13
14
15
16
# File 'lib/git_compound/repository/remote_file/github_strategy.rb', line 13

def initialize(source, ref, file)
  super
  @uri = github_uri
end

Instance Method Details

#contentsObject



18
19
20
21
22
# 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?Boolean

Returns:

  • (Boolean)


28
29
30
31
# 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?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/git_compound/repository/remote_file/github_strategy.rb', line 24

def reachable?
  @source.match(/#{GITHUB_PATTERN}/) ? true : false
end