class GitHub::Repo

Public Class Methods

get(information, o_type = :user) click to toggle source
# File lib/github-api-client/repo.rb, line 20
def self.get(information, o_type = :user)
  #FIXME: permalink column must be present, comparing url's is surely not the most efficient way for the db
  conditions = {:name => information.split('/').last}
  if o_type == :user
    conditions.merge! :owner_id => GitHub::User.find_or_create_by_login(information.split('/').first).id, :owner_type => 'GitHub::User'
  else
    conditions.merge! :owner_id => GitHub::Organization.find_or_create_by_login(information.split('/').first).id, :owner_type => 'GitHub::Organization'
  end
  if r = GitHub::Repo.where(conditions).first
    r.get
  else
    r = GitHub::Repo.new(conditions).get
    p r.parent
    r
  end
end

Public Instance Methods

fetch(*things) click to toggle source
# File lib/github-api-client/repo.rb, line 37
def fetch(*things)
  things.each do |thing|
    case thing
      when :self then get
      when :watchers then get_watchers
    end
  end
  self
end
fork?() click to toggle source
# File lib/github-api-client/repo.rb, line 95
def fork?
  b_fork
end
get() click to toggle source
# File lib/github-api-client/repo.rb, line 7
def get
  parser = case self.owner_type
    when 'GitHub::User'
      :repo_get
    when 'GitHub::Organization'
      :org_repo_get
  end
  self.update_attributes GitHub::Base.parse_attributes(parser, 
    YAML::load(
      GitHub::Browser.get("/repos/show/#{self.permalink}"))['repository'])
  self
end
organization_login=(organization) click to toggle source
# File lib/github-api-client/repo.rb, line 71
def organization_login=(organization)
  if organization
    self.owner = Organization.find_or_create_by_login(organization)
  end
end
owner_login=(user) click to toggle source
# File lib/github-api-client/repo.rb, line 65
def owner_login=(user)
  if user
    self.owner = GitHub::User.find_or_create_by_login(user)
  end
end
parent=(permalink) click to toggle source
# File lib/github-api-client/repo.rb, line 77
def parent=(permalink)
  #FIXME: parent repo does not allow organization to be owner ATM
  owner = GitHub::User.find_or_create_by_login permalink.split('/').first
  name = permalink.split('/').last
  repo = GitHub::Repo.where(:owner_id => owner.id, :owner_type => 'GitHub::Repo', :name => name).first
  repo ||= GitHub::Repo.create(:owner => owner, :name => name)
  self.parent_id = repo.id
end

Private Instance Methods

get_watchers() click to toggle source
# File lib/github-api-client/repo.rb, line 48
def get_watchers
  watchers = YAML::load(GitHub::Browser.get("/repos/show/#{self.permalink}/watchers"))['watchers']
  puts "Fetching watchers for #{"repo".color(:blue).bright} #{self.permalink.dup.color(:green).bright}"
  i, count = 0, watchers.count.to_s.color(:green).bright
  self.transaction do
    watchers.each do |watcher|
      i += 1
      attr = {:login => watcher}
      self.association(:watchers).find_or_create(GitHub::User.find_or_create_by_login(attr))
      print "\r#{i.to_s.color(:blue).bright}/#{count}"
    end
  end
  puts nil
  self
end