class GhostAdapter::Command

Constants

EXECUTABLE

Attributes

alter[R]
database[R]
dry_run[R]
table[R]

Public Class Methods

new(alter:, table:, database: nil, dry_run: false) click to toggle source
# File lib/ghost_adapter/command.rb, line 5
def initialize(alter:, table:, database: nil, dry_run: false)
  @alter = alter
  @table = table
  @database = GhostAdapter.config.database || database
  @dry_run = dry_run
  validate_args_and_config!
end

Public Instance Methods

to_a() click to toggle source
# File lib/ghost_adapter/command.rb, line 13
def to_a
  [
    EXECUTABLE,
    *base_args,
    *config_args,
    *execute_arg
  ]
end

Private Instance Methods

base_args() click to toggle source
# File lib/ghost_adapter/command.rb, line 34
def base_args
  [
    "--alter=#{alter}",
    "--table=#{table}",
    "--database=#{database}"
  ]
end
config_args() click to toggle source
# File lib/ghost_adapter/command.rb, line 42
def config_args
  context = {
    pid: $PID,
    table: table,
    database: database,
    timestamp: Time.now.utc.to_i,
    unique_id: SecureRandom.uuid
  }

  GhostAdapter.config.as_args(context: context)
end
execute_arg() click to toggle source
# File lib/ghost_adapter/command.rb, line 54
def execute_arg
  dry_run ? [] : ['--execute']
end
validate_args_and_config!() click to toggle source
# File lib/ghost_adapter/command.rb, line 28
def validate_args_and_config!
  raise ArgumentError, 'alter cannot be nil' if alter.nil?
  raise ArgumentError, 'table cannot be nil' if table.nil?
  raise ArgumentError, 'database cannot be nil' if database.nil?
end