Class: Hub::Context::GithubProject

Inherits:
Struct
  • Object
show all
Defined in:
lib/hub/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GithubProject

Returns a new instance of GithubProject.



208
209
210
211
# File 'lib/hub/context.rb', line 208

def initialize(*args)
  super
  self.host ||= (local_repo || LocalRepo).default_host
end

Instance Attribute Details

#repo_dataObject

Returns the value of attribute repo_data.



206
207
208
# File 'lib/hub/context.rb', line 206

def repo_data
  @repo_data
end

Class Method Details

.from_url(url, local_repo) ⇒ Object



199
200
201
202
203
204
# File 'lib/hub/context.rb', line 199

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



228
229
230
# File 'lib/hub/context.rb', line 228

def ==(other)
  name_with_owner == other.name_with_owner
end

#git_url(options = {}) ⇒ Object



249
250
251
252
253
254
# File 'lib/hub/context.rb', line 249

def git_url(options = {})
  if options[:https] then "https://#{host}/"
  elsif options[:private] or private? then "git@#{host}:"
  else "git://#{host}/"
  end + name_with_owner + '.git'
end

#name_with_ownerObject



224
225
226
# File 'lib/hub/context.rb', line 224

def name_with_owner
  "#{owner}/#{name}"
end

#owned_by(new_owner) ⇒ Object



218
219
220
221
222
# File 'lib/hub/context.rb', line 218

def owned_by(new_owner)
  new_project = dup
  new_project.owner = new_owner
  new_project
end

#private?Boolean

Returns:

  • (Boolean)


213
214
215
216
# File 'lib/hub/context.rb', line 213

def private?
  repo_data ? repo_data.fetch('private') :
    host != (local_repo || LocalRepo).main_host
end

#remoteObject



232
233
234
# File 'lib/hub/context.rb', line 232

def remote
  local_repo.remotes.find { |r| r.project == self }
end

#web_url(path = nil) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/hub/context.rb', line 236

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