Class: Git::Object::AbstractObject
- Inherits:
-
Object
- Object
- Git::Object::AbstractObject
- Defined in:
- lib/git/object.rb
Overview
A base class for all Git objects
Instance Attribute Summary collapse
-
#mode
Returns the value of attribute mode.
-
#objectish
Returns the value of attribute objectish.
- #size
-
#type
Returns the value of attribute type.
Instance Method Summary collapse
-
#archive(file = nil, opts = {}) ⇒ String
Creates an archive of this object and writes it to a file.
- #blob? ⇒ Boolean
- #commit? ⇒ Boolean
-
#contents
Returns the raw content of this git object or streams it into a temporary file.
- #contents_array
- #diff(objectish)
- #grep(string, path_limiter = nil, opts = {})
-
#initialize(base, objectish) ⇒ AbstractObject
constructor
A new instance of AbstractObject.
- #log(count = 30)
- #sha
- #tag? ⇒ Boolean
- #to_s
- #tree? ⇒ Boolean
Constructor Details
#initialize(base, objectish) ⇒ AbstractObject
Returns a new instance of AbstractObject.
18 19 20 21 22 23 24 25 |
# File 'lib/git/object.rb', line 18 def initialize(base, objectish) @base = base @objectish = objectish.to_s @contents = nil @trees = nil @size = nil @sha = nil end |
Instance Attribute Details
#mode
Returns the value of attribute mode.
14 15 16 |
# File 'lib/git/object.rb', line 14 def mode @mode end |
#objectish
Returns the value of attribute objectish.
14 15 16 |
# File 'lib/git/object.rb', line 14 def objectish @objectish end |
#size
31 32 33 |
# File 'lib/git/object.rb', line 31 def size @size ||= object_repository.cat_file_size(@objectish) end |
#type
Returns the value of attribute type.
14 15 16 |
# File 'lib/git/object.rb', line 14 def type @type end |
Instance Method Details
#archive(file = nil, opts = {}) ⇒ String
Creates an archive of this object and writes it to a file
115 116 117 |
# File 'lib/git/object.rb', line 115 def archive(file = nil, opts = {}) object_repository.archive(@objectish, file, opts) end |
#blob? ⇒ Boolean
121 |
# File 'lib/git/object.rb', line 121 def blob? = false |
#commit? ⇒ Boolean
123 |
# File 'lib/git/object.rb', line 123 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.
72 73 74 75 76 77 78 |
# File 'lib/git/object.rb', line 72 def contents(&) if block_given? object_repository.cat_file_contents(@objectish, &) else @contents ||= object_repository.cat_file_contents(@objectish) end end |
#contents_array
80 81 82 |
# File 'lib/git/object.rb', line 80 def contents_array contents.split("\n") end |
#diff(objectish)
92 93 94 |
# File 'lib/git/object.rb', line 92 def diff(objectish) Git::Diff.new(@base, @objectish, objectish) end |
#grep(string, path_limiter = nil, opts = {})
88 89 90 |
# File 'lib/git/object.rb', line 88 def grep(string, path_limiter = nil, opts = {}) object_repository.grep(string, path_limiter, opts.merge(object: sha)) end |
#log(count = 30)
96 97 98 |
# File 'lib/git/object.rb', line 96 def log(count = 30) Git::Log.new(@base, count).object(@objectish) end |
#sha
27 28 29 |
# File 'lib/git/object.rb', line 27 def sha @sha ||= object_repository.rev_parse(@objectish) end |
#tag? ⇒ Boolean
125 |
# File 'lib/git/object.rb', line 125 def tag? = false |
#to_s
84 85 86 |
# File 'lib/git/object.rb', line 84 def to_s @objectish end |
#tree? ⇒ Boolean
119 |
# File 'lib/git/object.rb', line 119 def tree? = false |