mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
d451044ece
commit
a7cdaadd19
1 changed files with 13 additions and 5 deletions
|
@ -144,12 +144,16 @@ module Rails
|
||||||
# Collisions are handled by checking whether the destination file
|
# Collisions are handled by checking whether the destination file
|
||||||
# exists and either skipping the file, forcing overwrite, or asking
|
# exists and either skipping the file, forcing overwrite, or asking
|
||||||
# the user what to do.
|
# 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.
|
# Determine full paths for source and destination files.
|
||||||
source = source_path(relative_source)
|
source = source_path(relative_source)
|
||||||
destination = destination_path(relative_destination)
|
destination = destination_path(relative_destination)
|
||||||
destination_exists = File.exists?(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.
|
# Check for and resolve file collisions.
|
||||||
if destination_exists
|
if destination_exists
|
||||||
|
@ -209,9 +213,13 @@ module Rails
|
||||||
system("svn add #{destination}") if options[:svn]
|
system("svn add #{destination}") if options[:svn]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if the source and the destination file are identical.
|
# Checks if the source and the destination file are identical. If
|
||||||
def identical?(source, destination)
|
# passed a block then the source file is a template that needs to first
|
||||||
IO.read(source) == IO.read(destination)
|
# 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
|
end
|
||||||
|
|
||||||
# Generate a file for a Rails application using an ERuby template.
|
# Generate a file for a Rails application using an ERuby template.
|
||||||
|
|
Loading…
Reference in a new issue