Class: Jekyll::GitHubMetadata::Repository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll-github-metadata/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_with_owner) ⇒ Repository

Returns a new instance of Repository.



34
35
36
37
38
# File 'lib/jekyll-github-metadata/repository.rb', line 34

def initialize(name_with_owner)
  @nwo   = name_with_owner
  @owner = nwo.split("/").first
  @name  = nwo.split("/").last
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/jekyll-github-metadata/repository.rb', line 4

def name
  @name
end

#nwoObject (readonly)

Returns the value of attribute nwo.



4
5
6
# File 'lib/jekyll-github-metadata/repository.rb', line 4

def nwo
  @nwo
end

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/jekyll-github-metadata/repository.rb', line 4

def owner
  @owner
end

Class Method Details

.def_hash_delegator(hash, key, method) ⇒ Object

Defines an instance method that delegates to a hash’s key

hash - a symbol representing the instance method to delegate to. The

instance method should return a hash or respond to #[]

key - the key to call within the hash method - (optional) the instance method the key should be aliased to.

If not specified, defaults to the hash key

Returns a symbol representing the instance method



15
16
17
18
19
# File 'lib/jekyll-github-metadata/repository.rb', line 15

def self.def_hash_delegator(hash, key, method)
  define_method(method) do
    public_send(hash)[key.to_s]
  end
end

Instance Method Details

#cnameObject



162
163
164
165
# File 'lib/jekyll-github-metadata/repository.rb', line 162

def cname
  return nil unless Pages.custom_domains_enabled?
  repo_pages_info["cname"]
end

#contributorsObject



113
114
115
# File 'lib/jekyll-github-metadata/repository.rb', line 113

def contributors
  memoize_value :@contributors, Value.new(proc { |c| c.contributors(nwo) })
end

#default_user_domainObject



152
153
154
155
156
157
158
159
160
# File 'lib/jekyll-github-metadata/repository.rb', line 152

def default_user_domain
  if github_repo?
    "#{owner}.#{Pages.github_hostname}".downcase
  elsif Pages.enterprise?
    Pages.pages_hostname.downcase
  else
    "#{owner}.#{Pages.pages_hostname}".downcase
  end
end

#github_repo?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/jekyll-github-metadata/repository.rb', line 133

def github_repo?
  !Pages.enterprise? && owner.eql?("github")
end

#html_urlObject



167
168
169
# File 'lib/jekyll-github-metadata/repository.rb', line 167

def html_url
  @html_url ||= (repo_pages_info["html_url"] || repo_compat.pages_url).chomp("/")
end

#issues_urlObject



91
92
93
# File 'lib/jekyll-github-metadata/repository.rb', line 91

def issues_url
  "#{repository_url}/issues" if repo_info["has_issues"]
end

#latest_releaseObject



121
122
123
# File 'lib/jekyll-github-metadata/repository.rb', line 121

def latest_release
  memoize_value :@latest_release, Value.new(proc { |c| c.latest_release(nwo) })
end

#organization_public_membersObject



107
108
109
110
111
# File 'lib/jekyll-github-metadata/repository.rb', line 107

def organization_public_members
  memoize_value :@organization_public_members, Value.new(proc do |c|
    c.organization_public_members(owner) if organization_repository?
  end)
end

#organization_repository?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/jekyll-github-metadata/repository.rb', line 99

def organization_repository?
  memoize_value :@is_organization_repository, Value.new(proc { |c| !!c.organization(owner) })
end

#owner_gravatar_urlObject



67
68
69
# File 'lib/jekyll-github-metadata/repository.rb', line 67

def owner_gravatar_url
  "#{owner_url}.png"
end

#owner_public_repositoriesObject



103
104
105
# File 'lib/jekyll-github-metadata/repository.rb', line 103

def owner_public_repositories
  memoize_value :@owner_public_repositories, Value.new(proc { |c| c.list_repos(owner, "type" => "public") })
end

#owner_urlObject



63
64
65
# File 'lib/jekyll-github-metadata/repository.rb', line 63

def owner_url
  "#{Pages.github_url}/#{owner}"
end

#primary?Boolean Also known as: user_page?

Returns:

  • (Boolean)


137
138
139
140
141
142
143
# File 'lib/jekyll-github-metadata/repository.rb', line 137

def primary?
  if Pages.enterprise?
    name.downcase == "#{owner.to_s.downcase}.#{Pages.github_hostname}"
  else
    user_page_domains.include? name.downcase
  end
end

#project_page?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/jekyll-github-metadata/repository.rb', line 129

def project_page?
  !user_page?
end

#releasesObject



117
118
119
# File 'lib/jekyll-github-metadata/repository.rb', line 117

def releases
  memoize_value :@releases, Value.new(proc { |c| c.releases(nwo) })
end

#releases_urlObject



87
88
89
# File 'lib/jekyll-github-metadata/repository.rb', line 87

def releases_url
  "#{repository_url}/releases"
end

#repo_clone_urlObject



71
72
73
# File 'lib/jekyll-github-metadata/repository.rb', line 71

def repo_clone_url
  "#{repository_url}.git"
end

#repo_compatObject



40
41
42
# File 'lib/jekyll-github-metadata/repository.rb', line 40

def repo_compat
  @repo_compat ||= Jekyll::GitHubMetadata::RepositoryCompat.new(self)
end

#repo_infoObject



44
45
46
47
48
49
# File 'lib/jekyll-github-metadata/repository.rb', line 44

def repo_info
  @repo_info ||= begin
    options = { :accept => "application/vnd.github.drax-preview+json" }
    (Value.new(proc { |c| c.repository(nwo, options) }).render || {})
  end
end

#repo_pages_infoObject



51
52
53
# File 'lib/jekyll-github-metadata/repository.rb', line 51

def repo_pages_info
  @repo_pages_info ||= (Value.new(proc { |c| c.pages(nwo, repo_pages_info_opts) }).render || {})
end

#repo_pages_info_optsObject



55
56
57
58
59
60
61
# File 'lib/jekyll-github-metadata/repository.rb', line 55

def repo_pages_info_opts
  if Pages.repo_pages_html_url_preview?
    { :accept => "application/vnd.github.mister-fantastic-preview+json" }
  else
    {}
  end
end

#repository_urlObject



75
76
77
# File 'lib/jekyll-github-metadata/repository.rb', line 75

def repository_url
  "#{owner_url}/#{name}"
end

#sourceObject



125
126
127
# File 'lib/jekyll-github-metadata/repository.rb', line 125

def source
  repo_pages_info["source"] || repo_compat.source
end

#tar_urlObject



83
84
85
# File 'lib/jekyll-github-metadata/repository.rb', line 83

def tar_url
  "#{repository_url}/tarball/#{git_ref}"
end

#uriObject



171
172
173
# File 'lib/jekyll-github-metadata/repository.rb', line 171

def uri
  @uri ||= URI(html_url)
end

#url_without_pathObject



175
176
177
# File 'lib/jekyll-github-metadata/repository.rb', line 175

def url_without_path
  uri.dup.tap { |u| u.path = "" }.to_s
end

#user_page_domainsObject



146
147
148
149
150
# File 'lib/jekyll-github-metadata/repository.rb', line 146

def user_page_domains
  domains = [default_user_domain]
  domains.push "#{owner}.github.com".downcase unless Pages.enterprise?
  domains
end

#wiki_urlObject



95
96
97
# File 'lib/jekyll-github-metadata/repository.rb', line 95

def wiki_url
  "#{repository_url}/wiki" if repo_info["has_wiki"]
end

#zip_urlObject



79
80
81
# File 'lib/jekyll-github-metadata/repository.rb', line 79

def zip_url
  "#{repository_url}/zipball/#{git_ref}"
end