Class: GitWorkingDirFeeder

Inherits:
Object
  • Object
show all
Includes:
Enumerable, GitSupport
Defined in:
lib/ruby_diff/git_working_dir_feeder.rb

Overview

A Feeder reads in files for RubyDiff’s processor to run over. GitWorkingDirFeeder reads them from a git repository. Usually used in conjunction with the GitFeeder.

Example Usage:

ruby_diff --git v0.1:lib --git-wd lib

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GitSupport

#git, #init_git

Constructor Details

#initialize(path) ⇒ GitWorkingDirFeeder

Expects something in the form of PATH

--file [PATH]


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

def initialize(path)
  @path = path
  
  path = File.expand_path(path) if path
  init_git(path || '.')
  @file_pattern = if @search_path == ''
    "**.rb"
  elsif @search_path =~ /\.rb#{File::SEPARATOR}$/
    # So appending each piece into the search path during init_git
    # causes the search path to always end with a /
    @search_path[0...-1]
  else
    File.join(@search_path,"**.rb")
  end
  
  @files = []
        
  FileUtils.cd(@working_dir) do
    git_list = git "ls-files"
    git_list.each_line do |line|
      file = line.chomp
      if File.fnmatch(@file_pattern, file)
        @files << file        
      end
    end
  end
  
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#eachObject



45
46
47
48
49
50
51
# File 'lib/ruby_diff/git_working_dir_feeder.rb', line 45

def each
  FileUtils.cd(@working_dir) do
    @files.each do |file|
      yield(open(file, 'r'){|io| io.read}, file)      
    end
  end
end