lib/rails/generators/rails/db/system/change/change_generator.rb in railties-6.0.0.beta3 vs lib/rails/generators/rails/db/system/change/change_generator.rb in railties-6.0.0.rc1
- old
+ new
@@ -33,21 +33,31 @@
def edit_database_config
template("config/databases/#{options[:database]}.yml", "config/database.yml")
end
def edit_gemfile
- database_gem_name, _ = gem_for_database
- gsub_file("Gemfile", all_database_gems_regex, database_gem_name)
+ 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
private
def all_database_gems
DATABASES.map { |database| gem_for_database(database) }
end
def all_database_gems_regex
all_database_gem_names = all_database_gems.map(&:first)
/(\b#{all_database_gem_names.join('\b|\b')}\b)/
+ end
+
+ def gem_entry_regex_for(gem_name)
+ /^gem.*\b#{gem_name}\b.*/
+ end
+
+ def gem_entry_for(*gem_name_and_version)
+ gem_name_and_version.map! { |segment| "'#{segment}'" }
+ "gem #{gem_name_and_version.join(", ")}"
end
end
end
end
end