Class: Metior::Actor Abstract

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

Overview

This class is abstract.

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

Represents an actor in a source code repository

Depending on the repository's VCS this may be for example an author or committer.

Author:

  • Sebastian Staudt

Direct Known Subclasses

Git::Actor, GitHub::Actor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AutoIncludeVCS

included

Constructor Details

#initialize(repo) ⇒ Actor

Creates a new actor linked to the given source code repository

Parameters:

  • repo (Repository)

    The repository this actor belongs to



50
51
52
53
54
# File 'lib/metior/actor.rb', line 50

def initialize(repo)
  @authored_commits  = CommitCollection.new
  @committed_commits = CommitCollection.new
  @repo              = repo
end

Instance Attribute Details

#authored_commitsCommitCollection (readonly) Also known as: commits

Returns The list of commits this actor has contributed to the source code repository.

Returns:

  • (CommitCollection)

    The list of commits this actor has contributed to the source code repository



24
25
26
# File 'lib/metior/actor.rb', line 24

def authored_commits
  @authored_commits
end

#committed_commitsCommitCollection (readonly)

Returns The list of commits this actor has committed to the source code repository.

Returns:

  • (CommitCollection)

    The list of commits this actor has committed to the source code repository



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

def committed_commits
  @committed_commits
end

#idString (readonly)

Returns A unqiue identifier for the actor.

Returns:

  • (String)

    A unqiue identifier for the actor



35
36
37
# File 'lib/metior/actor.rb', line 35

def id
  @id
end

#nameString (readonly)

Returns The full name of the actor.

Returns:

  • (String)

    The full name of the actor



32
33
34
# File 'lib/metior/actor.rb', line 32

def name
  @name
end

Class Method Details

.id_for(actor) ⇒ String

This method is abstract.

Different VCSs use different identifiers for users, so this method must be implemented for each supported VCS.

Extracts a unique identifier from the given, VCS dependent actor object

Parameters:

  • actor (Object)

    The actor object retrieved from the VCS

Returns:

  • (String)

    A unique identifier for the given actor

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/metior/actor.rb', line 43

def self.id_for(actor)
  raise NotImplementedError
end

Instance Method Details

#additionsFixnum

Returns the lines of code that have been added by this actor

Returns:

  • (Fixnum)

     The lines of code that have been added



59
60
61
# File 'lib/metior/actor.rb', line 59

def additions
  @authored_commits.additions
end

#deletionsFixnum

Returns the lines of code that have been deleted by this actor

Returns:

  • (Fixnum)

     The lines of code that have been deleted



66
67
68
# File 'lib/metior/actor.rb', line 66

def deletions
  @authored_commits.deletions
end

#inspectString

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

Returns:

  • (String)

     A minimal string representation for this actor



74
75
76
77
78
79
80
# File 'lib/metior/actor.rb', line 74

def inspect
  '#<%s:0x%x: @commits=%d @id="%s" @name="%s" @repo="%s"' %
    [
      self.class.name, __id__ * 2, @authored_commits.size, @id, @name,
      @repo.path
    ]
end

#modificationsFixnum

Returns the total of changed lines in all commits of this actor

Returns:

  • (Fixnum)

     The total number of changed lines



85
86
87
# File 'lib/metior/actor.rb', line 85

def modifications
  @authored_commits.modifications
end