Skip to content

Commit 0076e08

Browse files
committed
Merge pull request #31 from wbharding/master
Updates to make annotate smarter about when to touch a model
2 parents 8057b92 + f0c138c commit 0076e08

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

annotate.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini"]
1212
s.date = %q{2009-10-23}
13-
s.default_executable = %q{annotate}
13+
#s.default_executable = %q{annotate}
1414
s.description = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
1515
1616
s.executables = ["annotate"]

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ def annotate_one_file(file_name, info_block, options={})
119119
old_content = File.read(file_name)
120120

121121
# Ignore the Schema version line because it changes with each migration
122-
header = Regexp.new(/(^# Table name:.*?\n(#.*\n)*\n)/)
122+
header = Regexp.new(/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/)
123123
old_header = old_content.match(header).to_s
124124
new_header = info_block.match(header).to_s
125125

126-
if old_header == new_header
126+
old_columns = old_header && old_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
127+
new_columns = new_header && new_header.scan(/#[\t\s]+([\w\d]+)[\t\s]+\:([\d\w]+)/).sort
128+
129+
if old_columns == new_columns
127130
false
128131
else
129132
# Replace the old schema info with the new schema info

0 commit comments

Comments
 (0)