Class: Ardb::CLI::GenerateMigrationCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/cli.rb,
lib/ardb/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdout = nil, stderr = nil) ⇒ GenerateMigrationCommand

Returns a new instance of GenerateMigrationCommand.



237
238
239
240
241
242
243
# File 'lib/ardb/cli.rb', line 237

def initialize(argv, stdout = nil, stderr = nil)
  @argv   = argv
  @stdout = stdout || $stdout
  @stderr = stderr || $stderr

  @clirb = Ardb::CLIRB.new
end

Instance Attribute Details

#clirbObject (readonly)

Returns the value of attribute clirb.



235
236
237
# File 'lib/ardb/cli.rb', line 235

def clirb
  @clirb
end

Instance Method Details

#helpObject



263
264
265
266
# File 'lib/ardb/cli.rb', line 263

def help
  "Usage: ardb generate-migration [options] MIGRATION-NAME\n\n" \
  "Options: #{@clirb}"
end

#runObject



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/ardb/cli.rb', line 245

def run
  @clirb.parse!(@argv)
  begin
    require "ardb/migration"
    path = Ardb::Migration.new(@clirb.args.first).save!.file_path
    @stdout.puts "generated #{path}"
  rescue Ardb::Migration::NoIdentifierError => exception
    error = ArgumentError.new("MIGRATION-NAME must be provided")
    error.set_backtrace(exception.backtrace)
    raise error
  rescue StandardError => e
    @stderr.puts e
    @stderr.puts e.backtrace.join("\n")
    @stderr.puts "error generating migration"
    raise CommandExitError
  end
end