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

Inherits:
Base
  • Object
show all
Includes:
AppName, Rails::Generators::Database
Defined in:
lib/rails/generators/rails/db/system/change/change_generator.rb

Overview

:nodoc:

Constant Summary

Constants included from AppName

AppName::RESERVED_NAMES

Constants included from Rails::Generators::Database

Rails::Generators::Database::DATABASES, Rails::Generators::Database::JDBC_DATABASES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rails::Generators::Database

#convert_database_option_for_jruby, #gem_for_database

Methods inherited from Base

base_root, class_option, default_source_root, desc, exit_on_failure?, hide!, hook_for, inherited, namespace, remove_hook_for, source_root

Methods included from Actions

#add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor

Constructor Details

#initializeChangeGenerator

Returns a new instance of ChangeGenerator.



21
22
23
24
25
26
27
28
29
30
31
# File '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_rootObject



16
17
18
19
# File '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

#edit_database_configObject



33
34
35
# File '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_gemfileObject



37
38
39
40
41
# File '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