class RJGit::Blob
Attributes
get_name[R]
id[R]
jblob[R]
mode[R]
name[R]
path[R]
Public Class Methods
find_blob(repository, file_path, revstring=Constants::HEAD)
click to toggle source
Finds a particular Blob
in repository matching file_path
# File lib/blob.rb, line 73 def self.find_blob(repository, file_path, revstring=Constants::HEAD) jrepo = RJGit.repository_type(repository) last_commit_hash = jrepo.resolve(revstring) return nil if last_commit_hash.nil? walk = RevWalk.new(jrepo) jcommit = walk.parse_commit(last_commit_hash) treewalk = TreeWalk.new(jrepo) jtree = jcommit.get_tree treewalk.add_tree(jtree) treewalk.set_recursive(true) treewalk.set_filter(PathFilter.create(file_path)) if treewalk.next jblob = walk.lookup_blob(treewalk.get_object_id(0)) if jblob mode = RJGit.get_file_mode_with_path(jrepo, file_path, jtree) Blob.new(jrepo, mode, file_path, jblob) end else nil end end
mime_type(filename)
click to toggle source
# File lib/blob.rb, line 60 def self.mime_type(filename) guesses = MIME::Types.type_for(filename) rescue [] guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE end
new(repository, mode, path, jblob)
click to toggle source
# File lib/blob.rb, line 12 def initialize(repository, mode, path, jblob) @jrepo = RJGit.repository_type(repository) @jblob = jblob @path = path @name = @path ? File.basename(@path) : nil @mode = mode @id = ObjectId.toString(jblob.get_id) end
new_from_string(repository, contents)
click to toggle source
# File lib/blob.rb, line 65 def self.new_from_string(repository, contents) repository = RJGit.repository_type(repository) blob_id = RJGit::Plumbing::TreeBuilder.new(repository).write_blob(contents, true) walk = RevWalk.new(repository) Blob.new(repository, REG_FILE_TYPE, nil, walk.lookup_blob(blob_id)) end
Public Instance Methods
binary?()
click to toggle source
# File lib/blob.rb, line 46 def binary? RawText.is_binary(self.data.to_java_bytes) end
blame(options={})
click to toggle source
# File lib/blob.rb, line 32 def blame(options={}) @blame ||= RJGit::Porcelain.blame(@jrepo, @path, options) end
bytesize()
click to toggle source
The size of this blob in bytes
Returns Integer
# File lib/blob.rb, line 24 def bytesize @bytesize ||= @jrepo.open(@jblob).get_size end
data()
click to toggle source
The binary contents of this blob. Returns String
# File lib/blob.rb, line 38 def data @data ||= RJGit::Porcelain.cat_file(@jrepo, self) end
is_symlink?()
click to toggle source
# File lib/blob.rb, line 42 def is_symlink? @mode == SYMLINK_TYPE end
line_count()
click to toggle source
# File lib/blob.rb, line 50 def line_count self.binary? ? 0 : self.data.split("\n").size end
mime_type()
click to toggle source
The mime type of this file (based on the filename) Returns String
# File lib/blob.rb, line 56 def mime_type Blob.mime_type(self.name) end
size()
click to toggle source
# File lib/blob.rb, line 28 def size @size ||= bytesize end