Class: Pod::Source::GitHubDataProvider

Inherits:
AbstractDataProvider show all
Defined in:
lib/cocoapods-core/source/github_data_provider.rb

Overview

Data provider for a ‘Pod::Source` backed by a repository hosted on GitHub and accessed via the HTTP API. Only pure JSON repos using the `Specs` subdir to store the specifications are supported.

Instance Attribute Summary collapse

Data Source collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_id, branch = nil) ⇒ GitHubDataProvider

Returns a new instance of GitHubDataProvider.

Parameters:

  • repo_id (String)

    @see repo_id

  • branch (String) (defaults to: nil)

    @see branch



21
22
23
24
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 21

def initialize(repo_id, branch = nil)
  @repo_id = repo_id
  @branch = branch
end

Instance Attribute Details

#branchString (readonly)

Returns The branch of the repo if the default one shouldn’t be used.

Returns:

  • (String)

    The branch of the repo if the default one shouldn’t be used.



16
17
18
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 16

def branch
  @branch
end

#repo_idString (readonly)

Returns The identifier of the repository (user name and repo name) or the full URL of the repo.

Returns:

  • (String)

    The identifier of the repository (user name and repo name) or the full URL of the repo.



11
12
13
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 11

def repo_id
  @repo_id
end

Instance Method Details

#nameString

Returns The name of the Source. User name and repo.

Returns:

  • (String)

    The name of the Source. User name and repo.



33
34
35
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 33

def name
  GitHub.normalized_repo_id(repo_id)
end

#podsArray<String>

Returns The list of the name of all the Pods known to the Source.

Returns:

  • (Array<String>)

    The list of the name of all the Pods known to the Source.



46
47
48
49
50
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 46

def pods
  root_contents = get_github_contents('Specs')
  pods = dir_names(root_contents)
  pods.sort if pods
end

#specification(name, version) ⇒ Specification

Returns The specification for a given version of a Pod.

Parameters:

  • name (String)

    The name of the Pod.

  • version (String)

    The version of the Pod.

Returns:

  • (Specification)

    The specification for a given version of a Pod.

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 76

def specification(name, version)
  raise ArgumentError, 'No name' unless name
  raise ArgumentError, 'No version' unless version
  spec_content = specification_contents(name, version)
  if spec_content
    Pod::Specification.from_json(spec_content)
  end
end

#specification_contents(name, version) ⇒ Specification

Returns The contents of the specification for a given version of a Pod.

Parameters:

  • name (String)

    the name of the Pod.

  • version (String)

    the version of the Pod.

Returns:

  • (Specification)

    The contents of the specification for a given version of a Pod.

Raises:

  • (ArgumentError)


94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 94

def specification_contents(name, version)
  raise ArgumentError, 'No name' unless name
  raise ArgumentError, 'No version' unless version
  path = "Specs/#{name}/#{version}/#{name}.podspec.json"
  file_contents = get_github_contents(path)
  if file_contents
    if file_contents['encoding'] == 'base64'
      require 'base64'
      Base64.decode64(file_contents['content'])
    end
  end
end

#typeString

Returns The user friendly type of the source.

Returns:

  • (String)

    The user friendly type of the source.



39
40
41
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 39

def type
  'GitHub API'
end

#versions(name) ⇒ Array<String>

Returns All the available versions of a given Pod, sorted from highest to lowest.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Array<String>)

    All the available versions of a given Pod, sorted from highest to lowest.

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
66
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 58

def versions(name)
  raise ArgumentError, 'No name' unless name
  contents = get_github_contents("Specs/#{name}")
  pre_vers = dir_names(contents)
  return nil if pre_vers.nil?
  pre_vers.each do |v|
    Version.new(v)
  end.sort.reverse.map(&:to_s)
end