Class: RJGit::Blob
- Inherits:
-
Object
- Object
- RJGit::Blob
- Defined in:
- lib/blob.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#jblob ⇒ Object
readonly
Returns the value of attribute jblob.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.find_blob(repository, file_path, revstring = Constants::HEAD) ⇒ Object
Finds a particular Blob in repository matching file_path.
- .mime_type(filename) ⇒ Object
- .new_from_string(repository, contents) ⇒ Object
Instance Method Summary collapse
- #blame(options = {}) ⇒ Object
-
#bytesize ⇒ Object
The size of this blob in bytes.
-
#data ⇒ Object
The binary contents of this blob.
-
#initialize(repository, mode, path, jblob) ⇒ Blob
constructor
A new instance of Blob.
- #is_symlink? ⇒ Boolean
-
#mime_type ⇒ Object
The mime type of this file (based on the filename) Returns String.
- #size ⇒ Object
Constructor Details
#initialize(repository, mode, path, jblob) ⇒ Blob
Returns a new instance of Blob.
10 11 12 13 14 15 16 17 |
# File 'lib/blob.rb', line 10 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/blob.rb', line 7 def id @id end |
#jblob ⇒ Object (readonly)
Returns the value of attribute jblob.
7 8 9 |
# File 'lib/blob.rb', line 7 def jblob @jblob end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/blob.rb', line 7 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/blob.rb', line 7 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/blob.rb', line 7 def path @path end |
Class Method Details
.find_blob(repository, file_path, revstring = Constants::HEAD) ⇒ Object
Finds a particular Blob in repository matching file_path
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/blob.rb', line 63 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.objectId(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) ⇒ Object
50 51 52 53 |
# File 'lib/blob.rb', line 50 def self.mime_type(filename) guesses = MIME::Types.type_for(filename) rescue [] guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE end |
.new_from_string(repository, contents) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/blob.rb', line 55 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 |
Instance Method Details
#blame(options = {}) ⇒ Object
30 31 32 |
# File 'lib/blob.rb', line 30 def blame(={}) @blame ||= RJGit::Porcelain.blame(@jrepo, @path, ) end |
#bytesize ⇒ Object
The size of this blob in bytes
Returns Integer
22 23 24 |
# File 'lib/blob.rb', line 22 def bytesize @bytesize ||= @jrepo.open(@jblob).get_size end |
#data ⇒ Object
The binary contents of this blob. Returns String
36 37 38 |
# File 'lib/blob.rb', line 36 def data @data ||= RJGit::Porcelain.cat_file(@jrepo, @jblob) end |
#is_symlink? ⇒ Boolean
40 41 42 |
# File 'lib/blob.rb', line 40 def is_symlink? @mode == SYMLINK_TYPE end |
#mime_type ⇒ Object
The mime type of this file (based on the filename) Returns String
46 47 48 |
# File 'lib/blob.rb', line 46 def mime_type Blob.mime_type(self.name) end |
#size ⇒ Object
26 27 28 |
# File 'lib/blob.rb', line 26 def size @size ||= bytesize end |