Class: GitFeeder
- Inherits:
-
Object
- Object
- GitFeeder
- Includes:
- Enumerable, GitSupport
- Defined in:
- lib/ruby_diff/git_feeder.rb
Overview
A Feeder reads in files for RubyDiff’s processor to run over. GitFeeder reads them from a git repository.
Example Usage:
ruby_diff --git v0.1:lib --git v0.1:lib
ruby_diff --git HEAD^2 --git HEAD^1 --git HEAD
Defined Under Namespace
Classes: GitFile
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(path) ⇒ GitFeeder
constructor
Expects something in the form of REV:PATH –git REV:.
Methods included from GitSupport
Constructor Details
#initialize(path) ⇒ GitFeeder
Expects something in the form of REV:PATH
--git REV:[PATH]
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 44 45 46 47 48 |
# File 'lib/ruby_diff/git_feeder.rb', line 18 def initialize(path) @path = path rev,path = path.split(":",2) raise ArgumentError.new("Must supply a git revision") unless rev path = File.(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-tree -r #{rev}" git_list.each_line do |line| file = GitFile.new(*line.chomp.split(/\s+/,4)) if file.type == 'blob' and File.fnmatch(@file_pattern, file.name) @files << file end end end end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
10 11 12 |
# File 'lib/ruby_diff/git_feeder.rb', line 10 def files @files end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/ruby_diff/git_feeder.rb', line 11 def path @path end |
Instance Method Details
#each ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/ruby_diff/git_feeder.rb', line 50 def each FileUtils.cd(@working_dir) do @files.each do |file| code = git "show #{file.hash}" yield(code, file.name) end end end |