Class: Charming::Generators::DatabaseInstaller
- Inherits:
-
Object
- Object
- Charming::Generators::DatabaseInstaller
- Defined in:
- lib/charming/generators/database_installer.rb
Overview
DatabaseInstaller implements ‘charming db:install sqlite3`. It adds database support to an existing Charming app by creating `config/database.rb`, `app/models/application_record.rb`, `db/migrate/`, and `db/seeds.rb`, and patching the gemspec and root loader to include the new dependencies and the `app/models` autoload directory.
Instance Method Summary collapse
-
#initialize(database, out:, destination:) ⇒ DatabaseInstaller
constructor
database is the adapter name (only “sqlite3” is currently supported).
-
#install ⇒ Object
Performs the install: writes the database config, application record, migrate directory, seeds file, and patches the gemspec + root loader.
Constructor Details
#initialize(database, out:, destination:) ⇒ DatabaseInstaller
database is the adapter name (only “sqlite3” is currently supported). out is the status-output stream. destination is the app root.
14 15 16 17 18 19 |
# File 'lib/charming/generators/database_installer.rb', line 14 def initialize(database, out:, destination:) @database = database @out = out @destination = destination @app_name = Name.new(app_name_from_gemspec) end |
Instance Method Details
#install ⇒ Object
Performs the install: writes the database config, application record, migrate directory, seeds file, and patches the gemspec + root loader. Idempotent: existing files are reported with “exist <path>” instead of being overwritten.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/charming/generators/database_installer.rb', line 24 def install raise Error, "Unsupported database: #{database.inspect}" unless database == "sqlite3" create_file("config/database.rb", database_config) create_file("app/models/application_record.rb", application_record) create_file("db/migrate/.keep", "") create_file("db/seeds.rb", %(# frozen_string_literal: true )) update_gemspec update_root_file end |