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



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

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.



18
19
20
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 18

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.



13
14
15
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 13

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.



35
36
37
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 35

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.



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

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)


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

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)


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

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.



41
42
43
# File 'lib/cocoapods-core/source/github_data_provider.rb', line 41

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)


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

def versions(name)
  raise ArgumentError, "No name" unless name
  contents = get_github_contents("Specs/#{name}")
  dir_names(contents)
end