Class: Charming::DatabaseCommands
- Inherits:
-
Object
- Object
- Charming::DatabaseCommands
- Defined in:
- lib/charming/database_commands.rb
Overview
DatabaseCommands implements the runtime side of ‘charming db:COMMAND` (other than `db:install`, which lives in DatabaseInstaller). It loads the app’s ‘config/database.rb`, delegates the actual work to ActiveRecord, and prints a short status line on success.
Instance Method Summary collapse
-
#initialize(command, out:, destination:) ⇒ DatabaseCommands
constructor
command is the subcommand string (e.g., “db:create”).
-
#run ⇒ Object
Dispatches the configured command.
Constructor Details
#initialize(command, out:, destination:) ⇒ DatabaseCommands
command is the subcommand string (e.g., “db:create”). out is the status-output stream. destination is the app root for resolving ‘config/database.rb` and `db/`.
12 13 14 15 16 |
# File 'lib/charming/database_commands.rb', line 12 def initialize(command, out:, destination:) @command = command @out = out @destination = destination end |
Instance Method Details
#run ⇒ Object
Dispatches the configured command. Raises Generators::Error for unknown commands.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/charming/database_commands.rb', line 19 def run case command when "db:create" then create when "db:migrate" then migrate when "db:rollback" then rollback when "db:drop" then drop when "db:seed" then seed else raise Generators::Error, "Unknown database command: #{command}" end end |