Sha256: f74618918d5a30f015f705b1be04f6bb3a448ef2db27bb952a0ff22b679383bc

Contents?: true

Size: 1.38 KB

Versions: 39

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Rails
  module Generators
    module AppName # :nodoc:
      RESERVED_NAMES = %w(application destroy plugin runner test)

      private
        def app_name
          @app_name ||= original_app_name.parameterize(preserve_case: true).underscore
        end

        def original_app_name
          @original_app_name ||= (options[:name] || File.basename(destination_root))
        end

        def app_const_base
          @app_const_base ||= app_name.gsub(/\W/, "_").squeeze("_").camelize
        end
        alias :camelized :app_const_base

        def app_const
          @app_const ||= "#{app_const_base}::Application"
        end

        def valid_const?
          if /^\d/.match?(app_const)
            raise Error, "Invalid application name #{original_app_name}. Please give a name which does not start with numbers."
          elsif RESERVED_NAMES.include?(original_app_name)
            raise Error, "Invalid application name #{original_app_name}. Please give a " \
                         "name which does not match one of the reserved rails " \
                         "words: #{RESERVED_NAMES.join(", ")}"
          elsif Object.const_defined?(app_const_base)
            raise Error, "Invalid application name #{original_app_name}, constant #{app_const_base} is already in use. Please choose another application name."
          end
        end
    end
  end
end

Version data entries

39 entries across 39 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/generators/app_name.rb
railties-8.0.1 lib/rails/generators/app_name.rb
railties-8.0.0.1 lib/rails/generators/app_name.rb
railties-7.2.2.1 lib/rails/generators/app_name.rb
railties-7.1.5.1 lib/rails/generators/app_name.rb
railties-8.0.0 lib/rails/generators/app_name.rb
railties-7.2.2 lib/rails/generators/app_name.rb
railties-7.1.5 lib/rails/generators/app_name.rb
railties-8.0.0.rc2 lib/rails/generators/app_name.rb
railties-7.2.1.2 lib/rails/generators/app_name.rb
railties-7.1.4.2 lib/rails/generators/app_name.rb
railties-8.0.0.rc1 lib/rails/generators/app_name.rb
railties-7.2.1.1 lib/rails/generators/app_name.rb
railties-7.1.4.1 lib/rails/generators/app_name.rb
railties-8.0.0.beta1 lib/rails/generators/app_name.rb
omg-railties-8.0.0.alpha9 lib/rails/generators/app_name.rb
omg-railties-8.0.0.alpha8 lib/rails/generators/app_name.rb
omg-railties-8.0.0.alpha7 lib/rails/generators/app_name.rb
omg-railties-8.0.0.alpha4 lib/rails/generators/app_name.rb
omg-railties-8.0.0.alpha3 lib/rails/generators/app_name.rb