Class: Gitrob::Github::Repository
- Inherits:
-
Object
- Object
- Gitrob::Github::Repository
- Defined in:
- lib/gitrob/github/repository.rb
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
- #contents ⇒ Object
- #description ⇒ Object
- #full_name ⇒ Object
-
#initialize(owner, name, http_client) ⇒ Repository
constructor
A new instance of Repository.
- #save_to_database!(organization, user = nil) ⇒ Object
- #to_model(organization, user = nil) ⇒ Object
- #url ⇒ Object
- #website ⇒ Object
Constructor Details
#initialize(owner, name, http_client) ⇒ Repository
Returns a new instance of Repository.
6 7 8 |
# File 'lib/gitrob/github/repository.rb', line 6 def initialize(owner, name, http_client) @owner, @name, @http_client = owner, name, http_client end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
5 6 7 |
# File 'lib/gitrob/github/repository.rb', line 5 def http_client @http_client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gitrob/github/repository.rb', line 5 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
5 6 7 |
# File 'lib/gitrob/github/repository.rb', line 5 def owner @owner end |
Instance Method Details
#contents ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gitrob/github/repository.rb', line 10 def contents if !@contents @contents = [] response = JSON.parse(http_client.do_get("/repos/#{owner}/#{name}/git/trees/master?recursive=1").body) response['tree'].each do |object| next unless object['type'] == 'blob' @contents << Blob.new(object['path'], object['size'], self) end end @contents rescue HttpClient::ClientError => ex if ex.status == 409 || ex.status == 404 @contents = [] else raise ex end end |
#description ⇒ Object
36 37 38 |
# File 'lib/gitrob/github/repository.rb', line 36 def description info['description'] end |
#full_name ⇒ Object
28 29 30 |
# File 'lib/gitrob/github/repository.rb', line 28 def full_name [owner, name].join('/') end |
#save_to_database!(organization, user = nil) ⇒ Object
56 57 58 59 60 |
# File 'lib/gitrob/github/repository.rb', line 56 def save_to_database!(organization, user = nil) self.to_model(organization, user).tap { |m| m.save } rescue DataMapper::SaveFailureError => e puts e.resource.errors.inspect end |
#to_model(organization, user = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gitrob/github/repository.rb', line 44 def to_model(organization, user = nil) Gitrob::Repo.new( :name => self.name, :owner_name => self.owner, :description => self.description, :website => self.website, :url => self.url, :organization => organization, :user => user ) end |
#url ⇒ Object
32 33 34 |
# File 'lib/gitrob/github/repository.rb', line 32 def url info['html_url'] end |
#website ⇒ Object
40 41 42 |
# File 'lib/gitrob/github/repository.rb', line 40 def website info['homepage'] end |