Fixed generator collisions for nested controller modules.

Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
Amol Hatwar 2008-05-13 16:02:56 -05:00 committed by Joshua Peek
parent 4562a5b57f
commit 2d372d7049
1 changed files with 16 additions and 9 deletions

View File

@ -154,28 +154,35 @@ HELP
# Ruby or Rails. In the future, expand to check other namespaces # Ruby or Rails. In the future, expand to check other namespaces
# such as the rest of the user's app. # such as the rest of the user's app.
def class_collisions(*class_names) def class_collisions(*class_names)
# Initialize some check varibles
last_class = Object
current_class = nil
name = nil
class_names.flatten.each do |class_name| class_names.flatten.each do |class_name|
# Convert to string to allow symbol arguments. # Convert to string to allow symbol arguments.
class_name = class_name.to_s class_name = class_name.to_s
# Skip empty strings. # Skip empty strings.
next if class_name.strip.empty? class_name.strip.empty? ? next : current_class = class_name
# Split the class from its module nesting. # Split the class from its module nesting.
nesting = class_name.split('::') nesting = class_name.split('::')
name = nesting.pop name = nesting.pop
# Extract the last Module in the nesting. # Extract the last Module in the nesting.
last = nesting.inject(Object) { |last, nest| last = nesting.inject(last_class) { |last, nest|
break unless last.const_defined?(nest) break unless last_class.const_defined?(nest)
last.const_get(nest) last_class = last_class.const_get(nest)
} }
# If the last Module exists, check whether the given end
# class exists and raise a collision if so. # If the last Module exists, check whether the given
if last and last.const_defined?(name.camelize) # class exists and raise a collision if so.
raise_class_collision(class_name)
end if last_class and last_class.const_defined?(name.camelize)
raise_class_collision(current_class)
end end
end end