Class: MultiGit::Blob::Builder

Inherits:
StringIO
  • Object
show all
Includes:
Base, MultiGit::Builder
Defined in:
lib/multi_git/blob.rb

Instance Method Summary collapse

Methods included from MultiGit::Builder

#to_builder

Methods included from Utils::AbstractMethods

#abstract

Methods included from Base

#type

Constructor Details

#initialize(content = nil) ⇒ Builder

Returns a new instance of Builder.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/multi_git/blob.rb', line 32

def initialize(content = nil)
  super()
  if content.kind_of? Blob
    self << content.content
  elsif content.kind_of? String
    self << content
  elsif content.kind_of? IO
    IO.copy_stream(content, self)
  elsif content
    raise ArgumentError
  end
end

Instance Method Details

#>>(repo) ⇒ Object



51
52
53
54
# File 'lib/multi_git/blob.rb', line 51

def >>(repo)
  rewind
  return repo.write(read)
end

#content=(value) ⇒ Object



47
48
49
# File 'lib/multi_git/blob.rb', line 47

def content=(value)
  self.string = value.dup
end

#oidObject



56
57
58
59
60
61
# File 'lib/multi_git/blob.rb', line 56

def oid
  dig = Digest::SHA1.new
  dig << "blob #{size}\0"
  dig << content
  return dig.hexdigest
end

#with_parent(parent, name) ⇒ File::Builder

Turns the blob into a file using the given parent and filename.

Parameters:

  • parent (Object)
  • name (String)

Returns:



67
68
69
# File 'lib/multi_git/blob.rb', line 67

def with_parent(parent, name)
  File::Builder.new(parent, name, self)
end