Skip to content

Instantly share code, notes, and snippets.

@jeremyf
Created February 12, 2010 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyf/303054 to your computer and use it in GitHub Desktop.
Save jeremyf/303054 to your computer and use it in GitHub Desktop.
Compare two files
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