Created
February 12, 2010 22:30
-
-
Save jeremyf/303054 to your computer and use it in GitHub Desktop.
Compare two files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pathname' | |
# Compares two files for "similar" look, ignoring | |
# where elements are in the document. | |
def collect_unique_lines(*args) | |
dir = Pathname.new(Rails.root.join('tmp')) | |
contents = File.read(dir.join(args.join('.'))).split("\n") | |
lines = [] | |
# proposed_lines = [] | |
contents.inject(lines) {|mem,string| | |
string.strip! | |
if string.empty? | |
mem | |
elsif string =~ /^\#/ | |
mem | |
else | |
mem << string | |
end | |
} | |
end | |
['production'].each do |rails_env| | |
['conductor.conf', 'conductor.common'].each do |filename_prefix| | |
@proposed, @live = nil, nil | |
@proposed = collect_unique_lines(filename_prefix, rails_env, 'proposed') | |
@live = collect_unique_lines(filename_prefix, rails_env, 'live') | |
if @proposed == @live | |
puts "MATCH Filename: #{filename_prefix}" | |
else | |
puts "NO MATCH: #{filename_prefix}" | |
puts "\tIN PROPOSED BUT NOT LIVE:" | |
puts "\t\t" << (@proposed.clone - @live.clone).join("\n\t\t") | |
puts "\tIN LIVE BUT NOT PROPOSED:" | |
puts "\t\t" << (@live.clone - @proposed.clone).join("\n\t\t") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment