Class: Git::Object::AbstractObject

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

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.



14
15
16
17
18
19
20
21
# File 'lib/git/object.rb', line 14

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.



10
11
12
# File 'lib/git/object.rb', line 10

def mode
  @mode
end

#objectish

Returns the value of attribute objectish.



10
11
12
# File 'lib/git/object.rb', line 10

def objectish
  @objectish
end

#size



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

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

#type

Returns the value of attribute type.



10
11
12
# File 'lib/git/object.rb', line 10

def type
  @type
end

Instance Method Details

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

creates an archive of this object (tree)



67
68
69
# File 'lib/git/object.rb', line 67

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

#blob?Boolean

Returns:

  • (Boolean)


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

def blob?; false; end

#commit?Boolean

Returns:

  • (Boolean)


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

def commit?; false; end

#contents(&block)

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.



37
38
39
40
41
42
43
# File 'lib/git/object.rb', line 37

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

#contents_array



45
46
47
# File 'lib/git/object.rb', line 45

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

#diff(objectish)



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

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

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



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

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)



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

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

#sha



23
24
25
# File 'lib/git/object.rb', line 23

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

#tag?Boolean

Returns:

  • (Boolean)


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

def tag?; false; end

#to_s



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

def to_s
  @objectish
end

#tree?Boolean

Returns:

  • (Boolean)


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

def tree?; false; end