Class: Git::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/git/object.rb

Overview

represents a git object

Defined Under Namespace

Classes: AbstractObject, Blob, Commit, Tag, Tree

Class Method Summary collapse

Class Method Details

.new(base, objectish, type = nil, is_tag = false) ⇒ Git::Object::AbstractObject

if we're calling this, we don't know what type it is yet so this is our little factory method

Parameters:

  • base (Git::Repository)

    the repository used to query object data

  • objectish (String)

    the object name, SHA, ref, or treeish path

  • type (String, nil) (defaults to: nil)

    object type hint: blob, commit, or tree

  • is_tag (Boolean) (defaults to: false)

    whether to construct a tag object

Returns:



638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/git/object.rb', line 638

def self.new(base, objectish, type = nil, is_tag = false) # rubocop:disable Style/OptionalBooleanParameter
  return new_tag(base, objectish) if is_tag

  type ||= object_repository_for(base).cat_file_type(objectish)
  # TODO: why not handle tag case here too?
  klass =
    case type
    when /blob/   then Blob
    when /commit/ then Commit
    when /tree/   then Tree
    end
  klass.new(base, objectish)
end