Class: ConflictChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/conflict_checker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.do_all_gemsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/conflict_checker.rb', line 41

def self.do_all_gems
  all = {}; Gem.source_index.latest_specs.map{|s| all[s.name] = s.lib_files}
  collisions = ConflictChecker.new.check all
  if collisions.length > 0
    puts "warning: gem_conflict_plugin: conflicts detected! (they may be expected) your rubygems have one or more gems with conflicting lib/* filenames..."
    for filename, gems in collisions
      print " \"#{filename}\" was found redundantly in the libs of these gems: "
      puts gems.map{|gem_name, file_name| "#{gem_name} (#{file_name})"}.join(', ')
    end
    puts
  else
    puts "all clean--your rubygems has no reported conflicting filenames"
  end
  collisions
end

Instance Method Details

#check(names_with_files) ⇒ Object

check some files expects input like :lib1 => ‘lib/file1.rb’, :lib2 => ‘lib/file2.rb’



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
36
37
38
39
# File 'lib/conflict_checker.rb', line 7

def check names_with_files
  existing_list = {}
  conflict_list = {}

  for name, files in names_with_files
    for file in files
      orig_file = file.dup
      file = file.split('/')[1..-1].join('/') # strip off lib/
      
      
      if file =~ /_plugin.rb$/ # ignore lib/rubygems_plugin.rb, which *can* be redundant across gems
        next
      end
      
      if file =~ /(.rb|.so)$/
        file = file.split('.')[0..-2].join('.') # strip off .rb .so
      else
       next # skip directories...
      end
      
      if existing_list[file]
        # add it to the bad list
        if conflict_list[file]
          conflict_list[file] << [name, orig_file] # add it to the list...
        else
         conflict_list[file] = [existing_list[file], [name, orig_file]]
       end
      end
      existing_list[file] = [name, orig_file]
    end
  end
  conflict_list
end