Class: Grit::GitRuby::Tree

Inherits:
GitObject show all
Defined in:
lib/grit/git-ruby/object.rb,
lib/grit/git-ruby/git_object.rb

Instance Attribute Summary collapse

Attributes inherited from GitObject

#repository

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GitObject

#sha1

Constructor Details

#initialize(entries = [], repository = nil) ⇒ Tree

Returns a new instance of Tree.



197
198
199
200
# File 'lib/grit/git-ruby/object.rb', line 197

def initialize(entries=[], repository = nil)
  @entry = entries
  @repository = repository
end

Instance Attribute Details

#entryObject

Returns the value of attribute entry.



180
181
182
# File 'lib/grit/git-ruby/object.rb', line 180

def entry
  @entry
end

Class Method Details

.from_raw(rawobject, repository = nil) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/grit/git-ruby/object.rb', line 182

def self.from_raw(rawobject, repository=nil)
  raw = StringIO.new(rawobject.content)

  entries = []
  while !raw.eof?
    mode      = Grit::GitRuby.read_bytes_until(raw, ' ')
    file_name = Grit::GitRuby.read_bytes_until(raw, "\0")
    raw_sha   = raw.read(20)
    sha = raw_sha.unpack("H*").first

    entries << DirectoryEntry.new(mode, file_name, sha)
  end
  new(entries, repository)
end

Instance Method Details

#actual_rawObject



212
213
214
# File 'lib/grit/git-ruby/object.rb', line 212

def actual_raw
  #@entry.collect { |e| e.raw.join(' '), e.name].join("\t") }.join("\n")
end

#raw_contentObject



206
207
208
209
210
# File 'lib/grit/git-ruby/object.rb', line 206

def raw_content
  # TODO: sort correctly
  #@entry.sort { |a,b| a.name <=> b.name }.
  @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
end

#typeObject



202
203
204
# File 'lib/grit/git-ruby/object.rb', line 202

def type
  :tree
end