Class: Snitch::SvnLook
- Inherits:
-
Object
- Object
- Snitch::SvnLook
- Defined in:
- lib/snitch/svnlook.rb
Overview
This is a wrapper around the svnlook command line utility. I saw someone else using it so I did. I haven’t looked around for other options but I will as I’m not a fan of relying on command line stuff.
svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101)
puts svnlook., svnlook.project # etc, etc, etc.
The svnlook bin file defaults to /usr/bin/svnlook. To override the location of svnlook, just pass in a third parameter to the new method like so:
svnlook = Snitch::SvnLook.new('/var/www/apps/yourapp/repos/', 101, '/usr/local/bin/svnlook')
Constant Summary collapse
- LOG_PREPEND =
'\n-{2}'
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
Instance Method Summary collapse
-
#affected ⇒ Object
Returns the affected files of the committed revision.
-
#author ⇒ Object
Does an svn look for the author of the commit.
-
#initialize(repository, revision, svn_look_path = nil) ⇒ SvnLook
constructor
A new instance of SvnLook.
-
#message ⇒ Object
Returns the message entered with the committed revision.
-
#project ⇒ Object
Returns a best guess of the projects name.
-
#to_s(which = :long) ⇒ Object
Outputs the SvnLook in a pretty format for pasting into campfire.
Constructor Details
#initialize(repository, revision, svn_look_path = nil) ⇒ SvnLook
Returns a new instance of SvnLook.
16 17 18 19 |
# File 'lib/snitch/svnlook.rb', line 16 def initialize(repository, revision, svn_look_path=nil) @repository, @revision, @svnlook = repository, revision, svn_look_path @svnlook = svn_look_path || '/usr/bin/svnlook' end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
14 15 16 |
# File 'lib/snitch/svnlook.rb', line 14 def repository @repository end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
14 15 16 |
# File 'lib/snitch/svnlook.rb', line 14 def revision @revision end |
Instance Method Details
#affected ⇒ Object
Returns the affected files of the committed revision
43 44 45 |
# File 'lib/snitch/svnlook.rb', line 43 def affected @affected ||= changed.inject('') { |str, line| str << " - #{line}"; str } end |
#author ⇒ Object
Does an svn look for the author of the commit. Can’t be in the fancy meta programming above because it needs to get a newline chopped off.
25 26 27 |
# File 'lib/snitch/svnlook.rb', line 25 def look(:author).chop end |
#message ⇒ Object
Returns the message entered with the committed revision
38 39 40 |
# File 'lib/snitch/svnlook.rb', line 38 def @message ||= log.split(%r{#{LOG_PREPEND}}).inject('') { |str, log_item| str << " - #{log_item.gsub(/-/, '').capitalize}"; str } end |
#project ⇒ Object
Returns a best guess of the projects name. Assumes that most will be /some/path/to/cabin/repos/ or /some/path/to/cabin. Will grab the last two folders in the path and remove any that are equal to “repos”.
32 33 34 35 |
# File 'lib/snitch/svnlook.rb', line 32 def project # @project ||= repository.split('/')[-2] @project ||= repository.split('/')[-2, 2].detect { |a| a != 'repos' } end |
#to_s(which = :long) ⇒ Object
Outputs the SvnLook in a pretty format for pasting into campfire
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/snitch/svnlook.rb', line 48 def to_s(which=:long) case which.to_s when 'long' "[#{project}] Revision #{revision} Committed by #{}:\n#{}\nChanged Files:\n#{affected}" when 'short' str = "[#{project}] Revision #{revision} Committed by #{}:" str += .size > 137 ? [0, (140 - str.size)] + '...' : str.gsub("\n", ' ') end end |