Class: FileFeeder

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruby_diff/file_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 --file old_version.rb --file new_version.rb
ruby_diff --file old_dir/ --file new_dir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileFeeder

Expects something in the form of PATH

--file [PATH]


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_diff/file_feeder.rb', line 15

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

Instance Attribute Details

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#eachObject



28
29
30
31
32
# File 'lib/ruby_diff/file_feeder.rb', line 28

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