Class: Metior::Commit Abstract

Inherits:
Object show all
Includes:
AutoIncludeVCS
Defined in:
lib/metior/commit.rb

Overview

This class is abstract.

It has to be subclassed to implement a commit representation for a specific VCS.

This class represents a commit in a source code repository

Although not all VCSs distinguish authors from committers this implementation forces a differentiation between the both.

Author:

  • Sebastian Staudt

Direct Known Subclasses

Git::Commit, GitHub::Commit

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AutoIncludeVCS

included

Constructor Details

#initialize(repo) ⇒ Commit

Creates a new commit instance linked to the given repository and branch

Parameters:

  • repo (Repository)

    The repository this commit belongs to



54
55
56
57
58
59
60
61
62
# File 'lib/metior/commit.rb', line 54

def initialize(repo)
  @additions      = nil
  @added_files    = nil
  @children       = []
  @deletions      = nil
  @deleted_files  = nil
  @modified_files = nil
  @repo           = repo
end

Instance Attribute Details

#authorActor

Returns This commit's author.

Returns:

  • (Actor)

    This commit's author



23
24
25
# File 'lib/metior/commit.rb', line 23

def author
  @author
end

#authored_dateTime (readonly)

Returns The date this commit has been authored.

Returns:

  • (Time)

    The date this commit has been authored



26
27
28
# File 'lib/metior/commit.rb', line 26

def authored_date
  @authored_date
end

#childrenArray<Object> (readonly)

Returns The unique identifiers of the children of this commit.

Returns:

  • (Array<Object>)

    The unique identifiers of the children of this commit



33
34
35
# File 'lib/metior/commit.rb', line 33

def children
  @children
end

#committed_dateTime (readonly)

Returns The date this commit has been committed.

Returns:

  • (Time)

    The date this commit has been committed



36
37
38
# File 'lib/metior/commit.rb', line 36

def committed_date
  @committed_date
end

#committerActor

Returns This commit's committer.

Returns:

  • (Actor)

    This commit's committer



39
40
41
# File 'lib/metior/commit.rb', line 39

def committer
  @committer
end

#idObject (readonly)

Returns A unique identifier of the commit in the repository.

Returns:

  • (Object)

    A unique identifier of the commit in the repository



29
30
31
# File 'lib/metior/commit.rb', line 29

def id
  @id
end

#messageString (readonly)

Returns The commit message of this commit.

Returns:

  • (String)

    The commit message of this commit



42
43
44
# File 'lib/metior/commit.rb', line 42

def message
  @message
end

#parentsArray<Object> (readonly)

Returns The unique identifiers of one or more more parents of this commit.

Returns:

  • (Array<Object>)

    The unique identifiers of one or more more parents of this commit



46
47
48
# File 'lib/metior/commit.rb', line 46

def parents
  @parents
end

#repoRepository (readonly)

Returns The repository this commit belongs to.

Returns:

  • (Repository)

    The repository this commit belongs to



49
50
51
# File 'lib/metior/commit.rb', line 49

def repo
  @repo
end

Instance Method Details

#add_child(child) ⇒ Object

Adds the unique identifier of a child of this commit to the list of child commits

Parameters:

  • child (Object)

    The unique identifier of the child commit to add



80
81
82
# File 'lib/metior/commit.rb', line 80

def add_child(child)
  @children << child
end

#added_filesArray<String>

Returns the paths of all files that have been modified in this commit

This will load the file stats from the repository if not done yet.

Returns:

  • (Array<String>)

    A list of file paths added in this commit

See Also:



90
91
92
93
# File 'lib/metior/commit.rb', line 90

def added_files
  load_file_stats if @added_files.nil?
  @added_files
end

#additionsFixnum

Returnes the number of lines of code added in this commit

Returns:

  • (Fixnum)

     The lines of code that have been added

See Also:



99
100
101
102
# File 'lib/metior/commit.rb', line 99

def additions
  load_line_stats if @additions.nil?
  @additions
end

#deleted_filesArray<String>

Returns the paths of all files that have been modified in this commit

This will load the file stats from the repository if not done yet.

Returns:

  • (Array<String>)

    A list of file paths deleted in this commit

See Also:



122
123
124
125
# File 'lib/metior/commit.rb', line 122

def deleted_files
  load_file_stats if @deleted_files.nil?
  @deleted_files
end

#deletionsFixnum

Returnes the number of lines of code deleted in this commit

Returns:

  • (Fixnum)

     The lines of code that have been deleted

See Also:



131
132
133
134
# File 'lib/metior/commit.rb', line 131

def deletions
  load_line_stats if @deletions.nil?
  @deletions
end

#inspectString

Creates a string representation for this commit without recursing into actor and repository details

Returns:

  • (String)

     A minimal string representation for this commit



172
173
174
175
176
177
178
# File 'lib/metior/commit.rb', line 172

def inspect
  '#<%s:0x%x: @author="%s" @committer="%s" @id="%s" @repo="%s" @subject="%s">' %
    [
      self.class.name, __id__ * 2, @author.id, @committer.id, @id,
      @repo.path, subject
    ]
end

#load_file_statsObject (protected)

This method is abstract.

Has to be implemented by VCS specific subclasses

Loads the file stats for this commit from the repository

Raises:

  • (NotImplementedError)


185
186
187
# File 'lib/metior/commit.rb', line 185

def load_file_stats
  raise NotImplementedError
end

#load_line_statsObject (protected)

This method is abstract.

Has to be implemented by VCS specific subclasses

Loads the line stats for this commit from the repository

Raises:

  • (NotImplementedError)


192
193
194
# File 'lib/metior/commit.rb', line 192

def load_line_stats
  raise NotImplementedError
end

#merge?Boolean

Returns whether this commits is a merge commit

Returns:

  • (Boolean)

    true if this commit is a merge commit



139
140
141
# File 'lib/metior/commit.rb', line 139

def merge?
  @parents.size > 1
end

#modificationsFixnum

Returns the total of changed lines in this commit

Returns:

  • (Fixnum)

     The total number of changed lines



146
147
148
# File 'lib/metior/commit.rb', line 146

def modifications
  additions + deletions
end

#modified_filesArray<String>

Returns the paths of all files that have been modified in this commit

This will load the file stats from the repository if not done yet.

Returns:

  • (Array<String>)

    A list of file paths modified in this commit

See Also:



156
157
158
159
# File 'lib/metior/commit.rb', line 156

def modified_files
  load_file_stats if @modified_files.nil?
  @modified_files
end

#subjectString

Returns the subject line of the commit message, i.e. the first line

Returns:

  • (String)

    The subject of the commit



164
165
166
# File 'lib/metior/commit.rb', line 164

def subject
  @message.split(/$/).first
end