Class: Gitrob::Github::Blob

Inherits:
Object
  • Object
show all
Defined in:
lib/gitrob/github/blob.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, size, repository) ⇒ Blob

Returns a new instance of Blob.



6
7
8
# File 'lib/gitrob/github/blob.rb', line 6

def initialize(path, size, repository)
  @path, @size, @repository = path, size, repository
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/gitrob/github/blob.rb', line 4

def path
  @path
end

#repositoryObject (readonly)

Returns the value of attribute repository.



4
5
6
# File 'lib/gitrob/github/blob.rb', line 4

def repository
  @repository
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/gitrob/github/blob.rb', line 4

def size
  @size
end

Instance Method Details

#dirnameObject



18
19
20
# File 'lib/gitrob/github/blob.rb', line 18

def dirname
  File.dirname(path)
end

#extensionObject



10
11
12
# File 'lib/gitrob/github/blob.rb', line 10

def extension
  File.extname(path)[1..-1]
end

#filenameObject



14
15
16
# File 'lib/gitrob/github/blob.rb', line 14

def filename
  File.basename(path)
end

#save_to_database!(organization, repository) ⇒ Object



36
37
38
# File 'lib/gitrob/github/blob.rb', line 36

def save_to_database!(organization, repository)
  self.to_model(organization, repository).tap { |m| m.save }
end

#to_model(organization, repository) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gitrob/github/blob.rb', line 26

def to_model(organization, repository)
  repository.blobs.new(
    :path           => self.path,
    :filename       => self.filename,
    :extension      => self.extension,
    :size           => self.size,
    :organization   => organization
  )
end

#urlObject



22
23
24
# File 'lib/gitrob/github/blob.rb', line 22

def url
  "https://github.com/#{URI.escape(repository.owner)}/#{URI.escape(repository.name)}/blob/master/#{URI.escape(path)}"
end