Check whether the given class names are already taken by user application
or Ruby on Rails.
# File railties/lib/rails/generators/base.rb, line 248
def class_collisions(*class_names) #:nodoc:
return unless behavior == :invoke
class_names.flatten.each do |class_name|
class_name = class_name.to_s
next if class_name.strip.empty?
# Split the class from its module nesting
nesting = class_name.split('::')
last_name = nesting.pop
# Extract the last Module in the nesting
last = nesting.inject(Object) do |last_module, nest|
break unless last_module.const_defined?(nest, false)
last_module.const_get(nest)
end
if last && last.const_defined?(last_name.camelize, false)
raise Error, "The name '#{class_name}' is either already used in your application " <<
"or reserved by Ruby on Rails. Please choose an alternative and run " <<
"this generator again."
end
end
end