diff options
author | Marcel Molina <marcel@vernix.org> | 2005-10-08 18:40:00 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2005-10-08 18:40:00 +0000 |
commit | a7cdaadd1933cb4565ab9c2de5996821d3748d0a (patch) | |
tree | 02eb217cb87ba24a7474a973983b74a458e9c620 /railties/lib/rails_generator/commands.rb | |
parent | d451044ece8254f41c2e2e569e31f13eb45014ce (diff) | |
download | rails-a7cdaadd1933cb4565ab9c2de5996821d3748d0a.tar.gz rails-a7cdaadd1933cb4565ab9c2de5996821d3748d0a.tar.bz2 rails-a7cdaadd1933cb4565ab9c2de5996821d3748d0a.zip |
Evaluate dynamic templates before checking if the new file is identical to the old one.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2494 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/commands.rb')
-rw-r--r-- | railties/lib/rails_generator/commands.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index e6795efdb9..f8a7e706a3 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -144,12 +144,16 @@ module Rails # Collisions are handled by checking whether the destination file # exists and either skipping the file, forcing overwrite, or asking # the user what to do. - def file(relative_source, relative_destination, file_options = {}) + def file(relative_source, relative_destination, file_options = {}, &block) # Determine full paths for source and destination files. source = source_path(relative_source) destination = destination_path(relative_destination) destination_exists = File.exists?(destination) - return logger.identical(relative_destination) if destination_exists and identical?(source, destination) + + # If source and destination are identical then we're done. + if destination_exists and identical?(source, destination, &block) + return logger.identical(relative_destination) + end # Check for and resolve file collisions. if destination_exists @@ -209,9 +213,13 @@ module Rails system("svn add #{destination}") if options[:svn] end - # Checks if the source and the destination file are identical. - def identical?(source, destination) - IO.read(source) == IO.read(destination) + # Checks if the source and the destination file are identical. If + # passed a block then the source file is a template that needs to first + # be evaluated before being compared to the destination. + def identical?(source, destination, &block) + source = block_given? ? File.open(source) {|sf| yield(sf)} : IO.read(source) + destination = IO.read(destination) + source == destination end # Generate a file for a Rails application using an ERuby template. |