123456789_123456789_123456789_123456789_123456789_

Class: Rails::Generators::Db::System::ChangeGenerator

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Rails::Generators::Base, Thor::Group
Instance Chain:
Inherits: Rails::Generators::Base
Defined in: railties/lib/rails/generators/rails/db/system/change/change_generator.rb

Constant Summary

::Rails::Generators::Database - Included

DATABASES, JDBC_DATABASES

::Rails::Generators::AppName - Included

RESERVED_NAMES

Class Attribute Summary

Class Method Summary

::Rails::Generators::Base - Inherited

.base_root

Returns the base root for a common set of generators.

.default_source_root

Returns the default source root for a given generator.

.desc

Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description.

.hide!

Convenience method to hide this generator from the available ones when running rails generator command.

.hook_for

Invoke a generator based on the value supplied by the user to the given option named “name”.

.namespace

Convenience method to get the namespace from the class name.

.remove_hook_for

Remove a previously added hook.

.source_root

Returns the source root for this generator using default_source_root as default.

.add_shebang_option!

Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang.

.banner

Use Rails default banner.

.base_name

Sets the base_name taking into account the current class namespace.

.default_aliases_for_option

Returns default aliases for the option name given doing a lookup in Rails::Generators.aliases.

.default_for_option

Returns default for the option name given doing a lookup in config.

.default_generator_root,
.default_value_for_option

Returns the default value for the option name given doing a lookup in Rails::Generators.options.

.generator_name

Removes the namespaces and get the generator name.

.usage_path,
.class_option
.inherited

Cache source root and add lib/generators/base/generator/templates to source paths.

.hooks

Keep hooks configuration that are used on prepare_for_invocation.

.prepare_for_invocation

Prepare class invocation to search on ::Rails namespace if a previous added hook is being used.

Instance Attribute Summary

Instance Method Summary

::Rails::Generators::AppName - Included

::Rails::Generators::Database - Included

::Rails::Generators::Base - Inherited

#class_collisions

Check whether the given class names are already taken by user application or Ruby on ::Rails.

#extract_last_module

Takes in an array of nested modules and extracts the last module.

#indent,
#module_namespacing

Wrap block with namespace of current application if namespace exists and is not skipped.

#namespace, #namespace_dirs, #namespaced_path, #wrap_with_namespace

::Rails::Generators::Actions - Included

#add_source

Add the given source to Gemfile

#application
#environment

Adds configuration code to a Rails runtime environment.

#gem

Adds a gem declaration to the Gemfile for the specified gem.

#gem_group

Wraps gem entries inside a group.

#generate

Runs another generator.

#git

Runs one or more git commands.

#github,
#initializer

Creates an initializer file in config/initializers/.

#lib

Creates a file in lib/.

#rails_command

Runs the specified Rails command.

#rake

Runs the specified Rake task.

#rakefile

Creates a Rake tasks file in lib/tasks/.

#readme

Reads the given file at the source root and prints it in the console.

#route

Make an entry in Rails routing file config/routes.rb.

#vendor

Creates a file in vendor/.

#append_file_with_newline

Append string to a file with a newline if necessary.

#execute_command

Runs the supplied command using either “rake …” or “rails …” based on the executor parameter provided.

#indentation

Indent the Gemfile to the depth of @indentation.

#log

Define log for backwards compatibility.

#match_file,
#optimize_indentation

Returns optimized string with indentation.

#quote

Always returns value in double quotes.

#rebase_indentation
#route_namespace_pattern,
#with_indentation

Manage Gemfile indentation for a DSL action block.

#initialize

Constructor Details

.newChangeGenerator

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 21

def initialize(*)
  super

  unless DATABASES.include?(options[:to])
    raise Error, "Invalid value for --to option. Supported preconfigurations are: #{DATABASES.join(", ")}."
  end

  opt = options.dup
  opt[:database] ||= opt[:to]
  self.options = opt.freeze
end

Class Method Details

.default_generator_root

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 16

def self.default_generator_root
  path = File.expand_path(File.join(base_name, "app"), base_root)
  path if File.exist?(path)
end

Instance Method Details

#all_database_gems (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 58

def all_database_gems
  DATABASES.map { |database| gem_for_database(database) }
end

#all_database_gems_regex (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 70

def all_database_gems_regex
  all_database_gem_names = all_database_gems.map(&:first)
  /(\b#{all_database_gem_names.join('\b|\b')}\b)/
end

#all_docker_builds (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 62

def all_docker_builds
  DATABASES.map { |database| docker_for_database_build(database).nil? ? nil : docker_for_database_build(database) }.compact!
end

#all_docker_builds_regex (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 75

def all_docker_builds_regex
  /(\b#{all_docker_builds.join('\b|\b')}\b)/
end

#all_docker_deploys (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 66

def all_docker_deploys
  DATABASES.map { |database| docker_for_database_deploy(database).nil? ? nil : docker_for_database_deploy(database) }.compact!
end

#all_docker_deploys_regex (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 79

def all_docker_deploys_regex
  /(\b#{all_docker_deploys.join('\b|\b')}\b)/
end

#edit_database_config

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 33

def edit_database_config
  template("config/databases/#{options[:database]}.yml", "config/database.yml")
end

#edit_dockerfile

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 43

def edit_dockerfile
  dockerfile_path = File.expand_path("Dockerfile", destination_root)
  return unless File.exist?(dockerfile_path)

  build_name = docker_for_database_build
  deploy_name = docker_for_database_deploy
  if build_name
    gsub_file("Dockerfile", all_docker_builds_regex, build_name)
  end
  if deploy_name
    gsub_file("Dockerfile", all_docker_deploys_regex, deploy_name)
  end
end

#edit_gemfile

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 37

def edit_gemfile
  name, version = gem_for_database
  gsub_file("Gemfile", all_database_gems_regex, name)
  gsub_file("Gemfile", gem_entry_regex_for(name), gem_entry_for(name, *version))
end

#gem_entry_for(*gem_name_and_version) (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 87

def gem_entry_for(*gem_name_and_version)
  gem_name_and_version.map! { |segment| "\"#{segment}\"" }
  "gem #{gem_name_and_version.join(", ")}"
end

#gem_entry_regex_for(gem_name) (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/rails/db/system/change/change_generator.rb', line 83

def gem_entry_regex_for(gem_name)
  /^gem.*\b#{gem_name}\b.*/
end