Class: Gash::Blob

Inherits:
Delegator
  • Object
show all
Includes:
Helpers
Defined in:
lib/gash.rb

Overview

A Blob represent a string:

blob = Gash::Blob.new(:content => "Some content")
blob # => "Some content"

Using SHA1

However, if you provide a SHA1 (and have a parent which is connected to a Gash-object) it will then load the content from the repo when needed:

blob = Gash::Blob.new(:sha1 => "1234" * 10, :parent => gash_OR_tree_connected_to_gash)
blob        # => #<Blob:1234123412341234123412341234123412341234>
blob.upcase # It's loaded when needed
#blob.load! # or forced with #load!
blob        # => "Content of the blob"

Tree#[]= automatically sets the parent to itself, so you don’t need to provide it then:

tree["FILE"] = Gash::Blob.new(:sha1 => a_sha1)

<strong>See also</strong>: Helpers, Tree

Instance Attribute Summary collapse

Attributes included from Helpers

#mode, #parent, #sha1

Instance Method Summary collapse

Methods included from Helpers

#blob?, #changed!, #changed?, #gash, #initialize, #tree?

Instance Attribute Details

#contentObject

Returns the value of attribute content.



166
167
168
# File 'lib/gash.rb', line 166

def content
  @content
end

Instance Method Details

#__getobj__Object Also known as: to_s

:nodoc:



177
178
179
# File 'lib/gash.rb', line 177

def __getobj__ #:nodoc:
  @content ||= @sha1 ? load! : ''
end

#inspectObject

:nodoc:



173
174
175
# File 'lib/gash.rb', line 173

def inspect #:nodoc:
  @content ? @content.inspect : (@sha1 ? "#<Blob:#{@sha1}>" : to_s.inspect) 
end

#load!Object

Loads the file from Git, unless it’s already been loaded.



169
170
171
# File 'lib/gash.rb', line 169

def load!
  @content ||= gash.send(:cat_file, @sha1)
end