Class: RJGit::Blob
- Inherits:
-
Object
- Object
- RJGit::Blob
- Defined in:
- lib/blob.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
(also: #get_name)
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
- #binary? ⇒ Boolean
- #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
- #line_count ⇒ Object
-
#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.
12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#id ⇒ Object (readonly) Also known as: get_name
Returns the value of attribute id.
8 9 10 |
# File 'lib/blob.rb', line 8 def id @id end |
#jblob ⇒ Object (readonly)
Returns the value of attribute jblob.
8 9 10 |
# File 'lib/blob.rb', line 8 def jblob @jblob end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/blob.rb', line 8 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/blob.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/blob.rb', line 8 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
60 61 62 63 |
# 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_from_string(repository, contents) ⇒ Object
65 66 67 68 69 70 |
# 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 |
Instance Method Details
#binary? ⇒ Boolean
46 47 48 |
# File 'lib/blob.rb', line 46 def binary? RawText.is_binary(self.data.to_java_bytes) end |
#blame(options = {}) ⇒ Object
32 33 34 |
# File 'lib/blob.rb', line 32 def blame(={}) @blame ||= RJGit::Porcelain.blame(@jrepo, @path, ) end |
#bytesize ⇒ Object
The size of this blob in bytes
Returns Integer
24 25 26 |
# File 'lib/blob.rb', line 24 def bytesize @bytesize ||= @jrepo.open(@jblob).get_size end |
#data ⇒ Object
The binary contents of this blob. Returns String
38 39 40 |
# File 'lib/blob.rb', line 38 def data @data ||= RJGit::Porcelain.cat_file(@jrepo, @jblob) end |
#is_symlink? ⇒ Boolean
42 43 44 |
# File 'lib/blob.rb', line 42 def is_symlink? @mode == SYMLINK_TYPE end |
#line_count ⇒ Object
50 51 52 |
# File 'lib/blob.rb', line 50 def line_count self.binary? ? 0 : self.data.split("\n").size end |
#mime_type ⇒ Object
The mime type of this file (based on the filename) Returns String
56 57 58 |
# File 'lib/blob.rb', line 56 def mime_type Blob.mime_type(self.name) end |
#size ⇒ Object
28 29 30 |
# File 'lib/blob.rb', line 28 def size @size ||= bytesize end |