Class: SVNFeeder

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruby_diff/svn_feeder.rb

Overview

A Feeder reads in files for RubyDiff’s processor to run over. FileFeeder reads them from the file system.

Example Usage:

ruby_diff --svn PREV:file.rb --svn new_version.rb
ruby_diff --svn http://project.server.org/lib --svn .

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SVNFeeder

Expects something in the form of PATH

--file [PATH]


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_diff/svn_feeder.rb', line 15

def initialize(path)
  @path = path
  
  # TODO: Add support for SVN date format
  if @path =~ /^(\d+)|HEAD|BASE|COMMITTED|PREV\:/
    parts = path.split(":",2)
    svn_path = parts.pop
    rev = parts.shift
  else
    svn_path = @path
    rev = nil
  end
  
  @svn_options = (rev ? "-r #{rev} " : " ")+svn_path
  
  @file_pattern = "**/*.rb"

  @files = []
  
  svn("ls -R #{@svn_options}").each_line do |file|
    file.chomp!
    @files << file if File.fnmatch(@file_pattern, file)
  end
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/ruby_diff/svn_feeder.rb', line 8

def files
  @files
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/ruby_diff/svn_feeder.rb', line 9

def path
  @path
end

Instance Method Details

#eachObject



40
41
42
43
44
45
# File 'lib/ruby_diff/svn_feeder.rb', line 40

def each
  @files.each do |file|
    cat_path = File.join(@svn_options, file)
    yield(svn("cat #{cat_path}"), file)
  end
end

#svn(command) ⇒ Object

issues a command to svn



49
50
51
52
53
54
55
# File 'lib/ruby_diff/svn_feeder.rb', line 49

def svn command
  output = `svn #{command} 2>&1`.chomp
  unless $?.success?
    raise RuntimeError, output
  end
  output
end