Class: Grit::GitRuby::Tag

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

Instance Attribute Summary collapse

Attributes inherited from GitObject

#repository, #sha

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.



337
338
339
340
341
342
343
344
345
# File 'lib/grit/git-ruby/git_object.rb', line 337

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

Instance Attribute Details

#messageObject

Returns the value of attribute message.



299
300
301
# File 'lib/grit/git-ruby/git_object.rb', line 299

def message
  @message
end

#objectObject

Returns the value of attribute object.



299
300
301
# File 'lib/grit/git-ruby/git_object.rb', line 299

def object
  @object
end

#object_typeObject

Returns the value of attribute object_type.



299
300
301
# File 'lib/grit/git-ruby/git_object.rb', line 299

def object_type
  @object_type
end

#tagObject

Returns the value of attribute tag.



299
300
301
# File 'lib/grit/git-ruby/git_object.rb', line 299

def tag
  @tag
end

#taggerObject

Returns the value of attribute tagger.



299
300
301
# File 'lib/grit/git-ruby/git_object.rb', line 299

def tagger
  @tagger
end

#typeObject



352
353
354
# File 'lib/grit/git-ruby/git_object.rb', line 352

def type
  :tag
end

Class Method Details

.from_raw(rawobject, repository = nil) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/grit/git-ruby/git_object.rb', line 302

def self.from_raw(rawobject, repository=nil)

  headers, message = rawobject.content.split(/\n\n/, 2)
  headers = headers.split(/\n/).map { |header| header.split(' ', 2) }

  object = ''
  type = ''
  tag = ''
  tagger = ''

  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
  end

  if not object && type && tag && tagger
    raise RuntimeError, "incomplete raw tag object"
  end
  new(object, type, tag, tagger, message, repository)
end

Instance Method Details

#raw_contentObject



347
348
349
350
# File 'lib/grit/git-ruby/git_object.rb', line 347

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