Class: GitHub::Repo

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/github-api-client/repo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(information, o_type = :user) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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.(information.split('/').first).id, :owner_type => 'GitHub::User'
  else
    conditions.merge! :owner_id => GitHub::Organization.(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

Instance Method Details

#fetch(*things) ⇒ Object



37
38
39
40
41
42
43
44
45
# 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?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/github-api-client/repo.rb', line 95

def fork?
  b_fork
end

#getObject



7
8
9
10
11
12
13
14
15
16
17
18
# 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) ⇒ Object



71
72
73
74
75
# File 'lib/github-api-client/repo.rb', line 71

def organization_login=(organization)
  if organization
    self.owner = Organization.(organization)
  end
end

#owner_login=(user) ⇒ Object



65
66
67
68
69
# File 'lib/github-api-client/repo.rb', line 65

def owner_login=(user)
  if user
    self.owner = GitHub::User.(user)
  end
end

#parent=(permalink) ⇒ Object



77
78
79
80
81
82
83
84
# 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. 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


86
87
88
# File 'lib/github-api-client/repo.rb', line 86

def permalink
  "#{owner.}/#{name}"
end

#permalink=(anything) ⇒ Object

For future, when sql will be find_or_create_by_permalink



91
92
93
# File 'lib/github-api-client/repo.rb', line 91

def permalink=(anything)
  @permalink = permalink
end