Class: Hub::Context::GithubProject
- Inherits:
-
Struct
- Object
- Struct
- Hub::Context::GithubProject
- Defined in:
- lib/hub/context.rb
Instance Attribute Summary collapse
-
#repo_data ⇒ Object
Returns the value of attribute repo_data.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #git_url(options = {}) ⇒ Object
-
#initialize(*args) ⇒ GithubProject
constructor
A new instance of GithubProject.
- #name_with_owner ⇒ Object
- #owned_by(new_owner) ⇒ Object
- #private? ⇒ Boolean
- #remote ⇒ Object
- #web_url(path = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ GithubProject
Returns a new instance of GithubProject.
221 222 223 224 225 226 |
# File 'lib/hub/context.rb', line 221 def initialize(*args) super self.name = self.name.tr(' ', '-') self.host ||= (local_repo || LocalRepo).default_host self.host = host.sub(/^ssh\./i, '') if 'ssh.github.com' == host.downcase end |
Instance Attribute Details
#repo_data ⇒ Object
Returns the value of attribute repo_data.
219 220 221 |
# File 'lib/hub/context.rb', line 219 def repo_data @repo_data end |
Class Method Details
.from_url(url, local_repo) ⇒ Object
212 213 214 215 216 217 |
# File 'lib/hub/context.rb', line 212 def self.from_url(url, local_repo) if local_repo.known_hosts.include? url.host _, owner, name = url.path.split('/', 4) GithubProject.new(local_repo, owner, name.sub(/\.git$/, ''), url.host) end end |
Instance Method Details
#==(other) ⇒ Object
243 244 245 |
# File 'lib/hub/context.rb', line 243 def ==(other) name_with_owner == other.name_with_owner end |
#git_url(options = {}) ⇒ Object
264 265 266 267 268 269 |
# File 'lib/hub/context.rb', line 264 def git_url( = {}) if [:https] then "https://#{host}/" elsif [:private] or private? then "git@#{host}:" else "git://#{host}/" end + name_with_owner + '.git' end |
#name_with_owner ⇒ Object
239 240 241 |
# File 'lib/hub/context.rb', line 239 def name_with_owner "#{owner}/#{name}" end |
#owned_by(new_owner) ⇒ Object
233 234 235 236 237 |
# File 'lib/hub/context.rb', line 233 def owned_by(new_owner) new_project = dup new_project.owner = new_owner new_project end |
#private? ⇒ Boolean
228 229 230 231 |
# File 'lib/hub/context.rb', line 228 def private? repo_data ? repo_data.fetch('private') : host != (local_repo || LocalRepo).main_host end |
#remote ⇒ Object
247 248 249 |
# File 'lib/hub/context.rb', line 247 def remote local_repo.remotes.find { |r| r.project == self } end |
#web_url(path = nil) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/hub/context.rb', line 251 def web_url(path = nil) project_name = name_with_owner if project_name.sub!(/\.wiki$/, '') unless '/wiki' == path path = if path =~ %r{^/commits/} then '/_history' else path.to_s.sub(/\w+/, '_\0') end path = '/wiki' + path end end "https://#{host}/" + project_name + path.to_s end |