instance method class_collisions

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

class_collisions(*class_names)

Check whether the given class names are already taken by Ruby or Rails. In the future, expand to check other namespaces such as the rest of the user’s app.

Parameters

class_names rest
Source
# File railties/lib/rails_generator/commands.rb, line 171
        def class_collisions(*class_names)
          path = class_names.shift
          class_names.flatten.each do |class_name|
            # Convert to string to allow symbol arguments.
            class_name = class_name.to_s

            # Skip empty strings.
            next if class_name.strip.empty?

            # Split the class from its module nesting.
            nesting = class_name.split('::')
            name = nesting.pop

            # Extract the last Module in the nesting.
            last = nesting.inject(Object) { |last, nest|
              break unless last.const_defined?(nest)
              last.const_get(nest)
            }

            # If the last Module exists, check whether the given
            # class exists and raise a collision if so.
            if last and last.const_defined?(name.camelize)
              raise_class_collision(class_name)
            end
          end
        end

Defined in railties/lib/rails_generator/commands.rb line 171 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::Generator::Commands::Create

Type at least 2 characters to search.

↑↓ navigate · open · esc close