adamsanderson / ruby_diff

Higher level ruby code comparison

This URL has Read+Write access

ruby_diff / lib / ruby_diff / file_feeder.rb
100644 35 lines (29 sloc) 0.755 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# A Feeder reads in files for RubyDiff's processor to
# run over. FileFeeder reads them from the file system.
#
# Example Usage:
# ruby_diff --file old_version.rb --file new_version.rb
# ruby_diff --file old_dir/ --file new_dir
class FileFeeder
  attr_accessor :files
  attr_accessor :path
  
  include Enumerable
  
  # Expects something in the form of PATH
  # --file [PATH]
  def initialize(path)
    @path = path
    
    if path =~ /^\s+$/
      @file_pattern = "**/*.rb"
    elsif File.file? path
      @file_pattern = path
    else
      @file_pattern = File.join(path, "**/*.rb")
    end
    @files = Dir[@file_pattern]
  end
    
  def each
    @files.each do |file|
      yield(open(file, 'r'){|io| io.read}, file)
    end
  end
 
end