Class: Subtrigger::Revision

Inherits:
Object
  • Object
show all
Defined in:
lib/subtrigger/revision.rb

Overview

A simple wrapper around the output of Subversion’s svnlook command.

This class will let you make simple queries against the properties of a Subversion revision. It parses its output into keys and values so you can perform operations on them.

Attributes

It knows about the following attributes:

  • Revision number

  • Author

  • Timestamp

  • Log message

  • changed directories

This works by passing in the number of the revision to use, the raw output of svnlook info and the raw output of svnlook dirs-changed.

Special attributes

Revision knows about changed projects. This is extracted from the list of changed directories. A project is a directory that is directly above a directory named trunk, branches or tags. So when a directory /internal/accounting/trunk is changed, the project /internal/accounting is reported.

Examples:

Example of raw input for info

john
2010-07-05 17:00:00 +0200 (Mon, 01 Jan 2010)
215
Description of log

Usage

@revision = Revision.new('...')
@revision.author    # => 'john'
@revision.message   # => 'Description of log'
@revision.date      # => (instance of Time)
@revision.projects  # => ['/project1', 'project2', ...]

Author:

  • Arjan van der Gaag

Since:

  • 0.3.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision_number, info, dirs_changed) ⇒ Revision

Returns a new instance of Revision.

Since:

  • 0.3.0



56
57
58
59
60
61
# File 'lib/subtrigger/revision.rb', line 56

def initialize(revision_number, info, dirs_changed)
  @attributes = { :number => revision_number.to_i }
  @raw = info
  @dirs_changed = dirs_changed.split
  parse
end

Instance Attribute Details

#attributesObject (readonly)

the parsed Hash of attributes for this revision

Since:

  • 0.3.0



54
55
56
# File 'lib/subtrigger/revision.rb', line 54

def attributes
  @attributes
end

#dirs_changedObject (readonly)

A list of all directories that were changed in this revision

Since:

  • 0.3.0



51
52
53
# File 'lib/subtrigger/revision.rb', line 51

def dirs_changed
  @dirs_changed
end

#rawObject (readonly)

The raw output of the svnlook command.

Since:

  • 0.3.0



48
49
50
# File 'lib/subtrigger/revision.rb', line 48

def raw
  @raw
end

Instance Method Details

#projectsArray<String>

Creates a list of directory paths in the repository that have changes and contain a trunk, branches or tags directory.

For example, a changed path in like /topdir/project_name/trunk would result in /topdir/project_name.

Returns:

  • (Array<String>)

    list of changed project paths

Since:

  • 0.3.0



77
78
79
80
81
82
# File 'lib/subtrigger/revision.rb', line 77

def projects
  pattern = /\/(trunk|branches|tags)/
  dirs_changed.grep(pattern).map do |dir|
    dir.split(pattern, 2).first
  end.uniq
end