Class: Charming::Database::Commands
- Inherits:
-
Object
- Object
- Charming::Database::Commands
- Defined in:
- lib/charming/database/commands.rb
Overview
Commands implements the runtime side of ‘charming db:COMMAND` (other than `db:install`, which lives in Generators::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:) ⇒ Commands
constructor
command is the subcommand string (e.g., “db:create”).
-
#run ⇒ Object
Dispatches the configured command.
Constructor Details
#initialize(command, out:, destination:) ⇒ Commands
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/`.
14 15 16 17 18 |
# File 'lib/charming/database/commands.rb', line 14 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.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/charming/database/commands.rb', line 21 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 |