Class: Jekyll::GitHubMetadata::Repository
- Inherits:
-
Object
- Object
- Jekyll::GitHubMetadata::Repository
- Extended by:
- Forwardable
- Defined in:
- lib/jekyll-github-metadata/repository.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nwo ⇒ Object
readonly
Returns the value of attribute nwo.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Class Method Summary collapse
-
.def_hash_delegator(hash, key, method) ⇒ Object
Defines an instance method that delegates to a hash’s key.
Instance Method Summary collapse
- #cname ⇒ Object
- #contributors ⇒ Object
- #default_user_domain ⇒ Object
- #github_repo? ⇒ Boolean
- #html_url ⇒ Object
-
#initialize(name_with_owner) ⇒ Repository
constructor
A new instance of Repository.
- #issues_url ⇒ Object
- #latest_release ⇒ Object
- #organization_public_members ⇒ Object
- #organization_repository? ⇒ Boolean
- #owner_gravatar_url ⇒ Object
- #owner_public_repositories ⇒ Object
- #owner_url ⇒ Object
- #primary? ⇒ Boolean (also: #user_page?)
- #project_page? ⇒ Boolean
- #releases ⇒ Object
- #releases_url ⇒ Object
- #repo_clone_url ⇒ Object
- #repo_compat ⇒ Object
- #repo_info ⇒ Object
- #repo_pages_info ⇒ Object
- #repo_pages_info_opts ⇒ Object
- #repository_url ⇒ Object
- #source ⇒ Object
- #tar_url ⇒ Object
- #uri ⇒ Object
- #url_without_path ⇒ Object
- #user_page_domains ⇒ Object
- #wiki_url ⇒ Object
- #zip_url ⇒ Object
Constructor Details
#initialize(name_with_owner) ⇒ Repository
Returns a new instance of Repository.
36 37 38 39 40 |
# File 'lib/jekyll-github-metadata/repository.rb', line 36 def initialize(name_with_owner) @nwo = name_with_owner @owner = nwo.split("/").first @name = nwo.split("/").last end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/jekyll-github-metadata/repository.rb', line 6 def name @name end |
#nwo ⇒ Object (readonly)
Returns the value of attribute nwo.
6 7 8 |
# File 'lib/jekyll-github-metadata/repository.rb', line 6 def nwo @nwo end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
6 7 8 |
# File 'lib/jekyll-github-metadata/repository.rb', line 6 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
17 18 19 20 21 |
# File 'lib/jekyll-github-metadata/repository.rb', line 17 def self.def_hash_delegator(hash, key, method) define_method(method) do public_send(hash)[key.to_s] end end |
Instance Method Details
#cname ⇒ Object
164 165 166 167 |
# File 'lib/jekyll-github-metadata/repository.rb', line 164 def cname return nil unless Pages.custom_domains_enabled? repo_pages_info["cname"] end |
#contributors ⇒ Object
115 116 117 |
# File 'lib/jekyll-github-metadata/repository.rb', line 115 def contributors memoize_value :@contributors, Value.new(proc { |c| c.contributors(nwo) }) end |
#default_user_domain ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/jekyll-github-metadata/repository.rb', line 154 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
135 136 137 |
# File 'lib/jekyll-github-metadata/repository.rb', line 135 def github_repo? !Pages.enterprise? && owner.eql?("github") end |
#html_url ⇒ Object
169 170 171 |
# File 'lib/jekyll-github-metadata/repository.rb', line 169 def html_url @html_url ||= (repo_pages_info["html_url"] || repo_compat.pages_url).chomp("/") end |
#issues_url ⇒ Object
93 94 95 |
# File 'lib/jekyll-github-metadata/repository.rb', line 93 def issues_url "#{repository_url}/issues" if repo_info["has_issues"] end |
#latest_release ⇒ Object
123 124 125 |
# File 'lib/jekyll-github-metadata/repository.rb', line 123 def latest_release memoize_value :@latest_release, Value.new(proc { |c| c.latest_release(nwo) }) end |
#organization_public_members ⇒ Object
109 110 111 112 113 |
# File 'lib/jekyll-github-metadata/repository.rb', line 109 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
101 102 103 |
# File 'lib/jekyll-github-metadata/repository.rb', line 101 def organization_repository? memoize_value :@is_organization_repository, Value.new(proc { |c| !!c.organization(owner) }) end |
#owner_gravatar_url ⇒ Object
69 70 71 |
# File 'lib/jekyll-github-metadata/repository.rb', line 69 def owner_gravatar_url "#{owner_url}.png" end |
#owner_public_repositories ⇒ Object
105 106 107 |
# File 'lib/jekyll-github-metadata/repository.rb', line 105 def owner_public_repositories memoize_value :@owner_public_repositories, Value.new(proc { |c| c.list_repos(owner, "type" => "public") }) end |
#owner_url ⇒ Object
65 66 67 |
# File 'lib/jekyll-github-metadata/repository.rb', line 65 def owner_url "#{Pages.github_url}/#{owner}" end |
#primary? ⇒ Boolean Also known as: user_page?
139 140 141 142 143 144 145 |
# File 'lib/jekyll-github-metadata/repository.rb', line 139 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
131 132 133 |
# File 'lib/jekyll-github-metadata/repository.rb', line 131 def project_page? !user_page? end |
#releases ⇒ Object
119 120 121 |
# File 'lib/jekyll-github-metadata/repository.rb', line 119 def releases memoize_value :@releases, Value.new(proc { |c| c.releases(nwo) }) end |
#releases_url ⇒ Object
89 90 91 |
# File 'lib/jekyll-github-metadata/repository.rb', line 89 def releases_url "#{repository_url}/releases" end |
#repo_clone_url ⇒ Object
73 74 75 |
# File 'lib/jekyll-github-metadata/repository.rb', line 73 def repo_clone_url "#{repository_url}.git" end |
#repo_compat ⇒ Object
42 43 44 |
# File 'lib/jekyll-github-metadata/repository.rb', line 42 def repo_compat @repo_compat ||= Jekyll::GitHubMetadata::RepositoryCompat.new(self) end |
#repo_info ⇒ Object
46 47 48 49 50 51 |
# File 'lib/jekyll-github-metadata/repository.rb', line 46 def repo_info @repo_info ||= begin = { :accept => "application/vnd.github.drax-preview+json" } (Value.new(proc { |c| c.repository(nwo, ) }).render || {}) end end |
#repo_pages_info ⇒ Object
53 54 55 |
# File 'lib/jekyll-github-metadata/repository.rb', line 53 def repo_pages_info @repo_pages_info ||= (Value.new(proc { |c| c.pages(nwo, repo_pages_info_opts) }).render || {}) end |
#repo_pages_info_opts ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/jekyll-github-metadata/repository.rb', line 57 def repo_pages_info_opts if Pages.repo_pages_html_url_preview? { :accept => "application/vnd.github.mister-fantastic-preview+json" } else {} end end |
#repository_url ⇒ Object
77 78 79 |
# File 'lib/jekyll-github-metadata/repository.rb', line 77 def repository_url "#{owner_url}/#{name}" end |
#source ⇒ Object
127 128 129 |
# File 'lib/jekyll-github-metadata/repository.rb', line 127 def source repo_pages_info["source"] || repo_compat.source end |
#tar_url ⇒ Object
85 86 87 |
# File 'lib/jekyll-github-metadata/repository.rb', line 85 def tar_url "#{repository_url}/tarball/#{git_ref}" end |
#uri ⇒ Object
173 174 175 |
# File 'lib/jekyll-github-metadata/repository.rb', line 173 def uri @uri ||= URI(html_url) end |
#url_without_path ⇒ Object
177 178 179 |
# File 'lib/jekyll-github-metadata/repository.rb', line 177 def url_without_path uri.dup.tap { |u| u.path = "" }.to_s end |
#user_page_domains ⇒ Object
148 149 150 151 152 |
# File 'lib/jekyll-github-metadata/repository.rb', line 148 def user_page_domains domains = [default_user_domain] domains.push "#{owner}.github.com".downcase unless Pages.enterprise? domains end |
#wiki_url ⇒ Object
97 98 99 |
# File 'lib/jekyll-github-metadata/repository.rb', line 97 def wiki_url "#{repository_url}/wiki" if repo_info["has_wiki"] end |
#zip_url ⇒ Object
81 82 83 |
# File 'lib/jekyll-github-metadata/repository.rb', line 81 def zip_url "#{repository_url}/zipball/#{git_ref}" end |