method
class_collisions
v3.0.0 -
Show latest stable
- Class:
Rails::Generators::Base
class_collisions(*class_names)protected
Check whether the given class names are already taken by user application or Ruby on Rails.
# File railties/lib/rails/generators/base.rb, line 245
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
# Hack to limit const_defined? to non-inherited on 1.9
extra = []
extra << false unless Object.method(:const_defined?).arity == 1
# Extract the last Module in the nesting
last = nesting.inject(Object) do |last, nest|
break unless last.const_defined?(nest, *extra)
last.const_get(nest)
end
if last && last.const_defined?(last_name.camelize, *extra)
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 Related methods
- Class methods
- base_root
- class_option
- default_source_root
- desc
- hook_for
- inherited
- namespace
- remove_hook_for
- source_root
- Protected methods
-
add_shebang_option! -
banner -
base_name -
default_aliases_for_option -
default_for_option -
default_value_for_option -
generator_name -
hooks -
prepare_for_invocation -
class_collisions