Class: Grit::GitRuby::Tag

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(object, type, tag, tagger, message, repository = nil) ⇒ Tag

Returns a new instance of Tag.


306
307
308
309
310
311
312
# File 'lib/grit/git-ruby/object.rb', line 306

def initialize(object, type, tag, tagger, repository=nil)
  @object = object
  @type = type
  @tag = tag
  @tagger = tagger
  @repository = repository
end

Instance Attribute Details

#messageObject

Returns the value of attribute message


277
278
279
# File 'lib/grit/git-ruby/object.rb', line 277

def message
  @message
end

#objectObject

Returns the value of attribute object


277
278
279
# File 'lib/grit/git-ruby/object.rb', line 277

def object
  @object
end

#tagObject

Returns the value of attribute tag


277
278
279
# File 'lib/grit/git-ruby/object.rb', line 277

def tag
  @tag
end

#taggerObject

Returns the value of attribute tagger


277
278
279
# File 'lib/grit/git-ruby/object.rb', line 277

def tagger
  @tagger
end

#typeObject

Returns the value of attribute type


277
278
279
# File 'lib/grit/git-ruby/object.rb', line 277

def type
  @type
end

Class Method Details

.from_raw(rawobject, repository = nil) ⇒ Object


279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/grit/git-ruby/object.rb', line 279

def self.from_raw(rawobject, repository=nil)
  headers, message = rawobject.content.split(/\n\n/, 2)
  headers = headers.split(/\n/).map { |header| header.split(/ /, 2) }
  headers.each do |key, value|
    case key
    when "object"
      object = value
    when "type"
      if !["blob", "tree", "commit", "tag"].include?(value)
        raise RuntimeError, "invalid type in tag"
      end
      type = value.to_sym
    when "tag"
      tag = value
    when "tagger"
      tagger = UserInfo.new(value)
    else
      warn "unknown header '%s' in tag" % \
        [key, rawobject.sha1.unpack("H*")[0]]
    end
    if not object && type && tag && tagger
      raise RuntimeError, "incomplete raw tag object"
    end
  end
  new(object, type, tag, tagger, repository)
end

Instance Method Details

#raw_contentObject


314
315
316
317
# File 'lib/grit/git-ruby/object.rb', line 314

def raw_content
  "object %s\ntype %s\ntag %s\ntagger %s\n\n" % \
    [@object, @type, @tag, @tagger] + @message
end