Class: Berkshelf::GithubLocation

Inherits:
GitLocation show all
Defined in:
lib/berkshelf/locations/github_location.rb

Constant Summary collapse

DEFAULT_PROTOCOL =
:git

Constants included from Location

Location::OPSCODE_COMMUNITY_API

Instance Attribute Summary collapse

Attributes inherited from GitLocation

#branch, #options, #ref, #rel, #uri

Attributes included from Location

#name, #version_constraint

Instance Method Summary collapse

Methods inherited from GitLocation

#download, tmpdir, #to_hash

Methods included from Location

#download, included, init, #to_hash, #to_json, #validate_cached

Constructor Details

#initialize(name, version_constraint, options = {}) ⇒ GithubLocation

Wraps GitLocation allowing the short form GitHub repo identifier to be used in place of the complete repo url.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :github (String)

    the GitHub repo identifier to clone

  • :protocol (#to_sym)

    the protocol with which to communicate with GitHub

See Also:



20
21
22
23
24
25
# File 'lib/berkshelf/locations/github_location.rb', line 20

def initialize(name, version_constraint, options = {})
  @repo_identifier = options.delete(:github)
  @protocol        = (options.delete(:protocol) || DEFAULT_PROTOCOL).to_sym
  options[:git]    = github_url
  super
end

Instance Attribute Details

#protocolObject

Returns the value of attribute protocol.



8
9
10
# File 'lib/berkshelf/locations/github_location.rb', line 8

def protocol
  @protocol
end

#repo_identifierObject

Returns the value of attribute repo_identifier.



9
10
11
# File 'lib/berkshelf/locations/github_location.rb', line 9

def repo_identifier
  @repo_identifier
end

Instance Method Details

#github_urlString

Returns the appropriate GitHub url given the specified protocol

Returns:

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/berkshelf/locations/github_location.rb', line 33

def github_url
  case protocol
  when :ssh
    "[email protected]:#{repo_identifier}.git"
  when :https
    "https://github.com/#{repo_identifier}.git"
  when :git
    "git://github.com/#{repo_identifier}.git"
  else
    raise UnknownGitHubProtocol.new(protocol)
  end
end

#to_sObject



46
47
48
49
50
51
# File 'lib/berkshelf/locations/github_location.rb', line 46

def to_s
  s = "#{self.class.location_key}: '#{repo_identifier}'"
  s << " with branch: '#{branch}'" if branch
  s << " over protocol: '#{protocol}'"
  s
end