Class: Git::Object::AbstractObject

Inherits:
Object
  • Object
show all
Defined in:
lib/git/object.rb

Overview

A base class for all Git objects

Direct Known Subclasses

Blob, Commit, Tag, Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, objectish) ⇒ AbstractObject

Returns a new instance of AbstractObject.



17
18
19
20
21
22
23
24
# File 'lib/git/object.rb', line 17

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.



13
14
15
# File 'lib/git/object.rb', line 13

def mode
  @mode
end

#objectish

Returns the value of attribute objectish.



13
14
15
# File 'lib/git/object.rb', line 13

def objectish
  @objectish
end

#size



30
31
32
# File 'lib/git/object.rb', line 30

def size
  @size ||= @base.lib.cat_file_size(@objectish)
end

#type

Returns the value of attribute type.



13
14
15
# File 'lib/git/object.rb', line 13

def type
  @type
end

Instance Method Details

#archive(file = nil, opts = {})

creates an archive of this object (tree)



70
71
72
# File 'lib/git/object.rb', line 70

def archive(file = nil, opts = {})
  @base.lib.archive(@objectish, file, opts)
end

#blob?Boolean

Returns:

  • (Boolean)


76
# File 'lib/git/object.rb', line 76

def blob? = false

#commit?Boolean

Returns:

  • (Boolean)


78
# File 'lib/git/object.rb', line 78

def commit? = false

#contents

Get the object's contents. If no block is given, the contents are cached in memory and returned as a string. If a block is given, it yields an IO object (via IO::popen) which could be used to read a large file in chunks.

Use this for large files so that they are not held in memory.



40
41
42
43
44
45
46
# File 'lib/git/object.rb', line 40

def contents(&)
  if block_given?
    @base.lib.cat_file_contents(@objectish, &)
  else
    @contents ||= @base.lib.cat_file_contents(@objectish)
  end
end

#contents_array



48
49
50
# File 'lib/git/object.rb', line 48

def contents_array
  contents.split("\n")
end

#diff(objectish)



61
62
63
# File 'lib/git/object.rb', line 61

def diff(objectish)
  Git::Diff.new(@base, @objectish, objectish)
end

#grep(string, path_limiter = nil, opts = {})



56
57
58
59
# File 'lib/git/object.rb', line 56

def grep(string, path_limiter = nil, opts = {})
  opts = { object: sha, path_limiter: path_limiter }.merge(opts)
  @base.lib.grep(string, opts)
end

#log(count = 30)



65
66
67
# File 'lib/git/object.rb', line 65

def log(count = 30)
  Git::Log.new(@base, count).object(@objectish)
end

#sha



26
27
28
# File 'lib/git/object.rb', line 26

def sha
  @sha ||= @base.lib.rev_parse(@objectish)
end

#tag?Boolean

Returns:

  • (Boolean)


80
# File 'lib/git/object.rb', line 80

def tag? = false

#to_s



52
53
54
# File 'lib/git/object.rb', line 52

def to_s
  @objectish
end

#tree?Boolean

Returns:

  • (Boolean)


74
# File 'lib/git/object.rb', line 74

def tree? = false