Class: Git::Object::AbstractObject Private
- Inherits:
-
Object
- Object
- Git::Object::AbstractObject
- Defined in:
- lib/git/object.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A base class for all Git objects
Instance Attribute Summary collapse
-
#mode ⇒ String?
private
The file mode from tree listings.
-
#objectish ⇒ String
private
The object name, SHA, ref, or treeish path.
-
#size ⇒ Integer
private
Returns the size of this object in bytes.
-
#type ⇒ String?
private
The git object type.
Instance Method Summary collapse
-
#archive(file = nil, opts = {}) ⇒ String
Creates an archive of this object and writes it to a file.
-
#blob? ⇒ Boolean
private
Returns whether this object is a blob.
-
#commit? ⇒ Boolean
private
Returns whether this object is a commit.
-
#contents
Returns the raw content of this git object or streams it into a temporary file.
-
#contents_array ⇒ Array<String>
private
Returns the object contents split into lines.
-
#diff(objectish) ⇒ Git::Diff
private
Returns a diff from this object to another object.
-
#grep(string, path_limiter = nil, opts = {}) ⇒ Hash<String, Array<Array(Integer, String)>>
private
Searches this object for matching tracked file contents.
-
#initialize(base, objectish) ⇒ AbstractObject
constructor
private
Creates a lazy wrapper for a git object.
-
#log(count = 30) ⇒ Git::Log
private
Returns a log scoped to this object.
-
#sha ⇒ String
private
Returns the resolved SHA for this object.
-
#tag? ⇒ Boolean
private
Returns whether this object is a tag.
-
#to_s ⇒ String
private
Returns the original object expression.
-
#tree? ⇒ Boolean
private
Returns whether this object is a tree.
Constructor Details
#initialize(base, objectish) ⇒ AbstractObject
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a lazy wrapper for a git object
43 44 45 46 47 48 49 50 |
# File 'lib/git/object.rb', line 43 def initialize(base, objectish) @base = base @objectish = objectish.to_s @contents = nil @trees = nil @size = nil @sha = nil end |
Instance Attribute Details
#mode ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file mode from tree listings.
26 27 28 |
# File 'lib/git/object.rb', line 26 def mode @mode end |
#objectish ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the object name, SHA, ref, or treeish path.
18 19 20 |
# File 'lib/git/object.rb', line 18 def objectish @objectish end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the size of this object in bytes
64 65 66 |
# File 'lib/git/object.rb', line 64 def size @size ||= object_repository.cat_file_size(@objectish) end |
#type ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the git object type.
22 23 24 |
# File 'lib/git/object.rb', line 22 def type @type end |
Instance Method Details
#archive(file = nil, opts = {}) ⇒ String
Creates an archive of this object and writes it to a file
228 229 230 |
# File 'lib/git/object.rb', line 228 def archive(file = nil, opts = {}) object_repository.archive(@objectish, file, opts) end |
#blob? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether this object is a blob
242 |
# File 'lib/git/object.rb', line 242 def blob? = false |
#commit? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether this object is a commit
248 |
# File 'lib/git/object.rb', line 248 def commit? = false |
#contents ⇒ String #contents {|file| ... } ⇒ Object
Returns the raw content of this git object or streams it into a temporary file
Without a block, the full content is buffered in memory and cached, then
returned as a String. With a block, git output is streamed directly to a
temporary file on disk — suitable for large objects.
105 106 107 108 109 110 111 |
# File 'lib/git/object.rb', line 105 def contents(&) if block_given? object_repository.cat_file_contents(@objectish, &) else @contents ||= object_repository.cat_file_contents(@objectish) end end |
#contents_array ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the object contents split into lines
117 118 119 |
# File 'lib/git/object.rb', line 117 def contents_array contents.split("\n") end |
#diff(objectish) ⇒ Git::Diff
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a diff from this object to another object
169 170 171 |
# File 'lib/git/object.rb', line 169 def diff(objectish) Git::Diff.new(@base, @objectish, objectish) end |
#grep(string, path_limiter = nil, opts = {}) ⇒ Hash<String, Array<Array(Integer, String)>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Searches this object for matching tracked file contents
Always searches this object's resolved SHA. A caller-provided :object
option is ignored.
158 159 160 |
# File 'lib/git/object.rb', line 158 def grep(string, path_limiter = nil, opts = {}) object_repository.grep(string, path_limiter, opts.merge(object: sha)) end |
#log(count = 30) ⇒ Git::Log
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a log scoped to this object
179 180 181 |
# File 'lib/git/object.rb', line 179 def log(count = 30) Git::Log.new(@base, count).object(@objectish) end |
#sha ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the resolved SHA for this object
56 57 58 |
# File 'lib/git/object.rb', line 56 def sha @sha ||= object_repository.rev_parse(@objectish) end |
#tag? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether this object is a tag
254 |
# File 'lib/git/object.rb', line 254 def tag? = false |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the original object expression
125 126 127 |
# File 'lib/git/object.rb', line 125 def to_s @objectish end |
#tree? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether this object is a tree
236 |
# File 'lib/git/object.rb', line 236 def tree? = false |