Class: Ardb::CLI::ConnectCommand

Inherits:
Object
  • Object
show all
Includes:
ValidCommand
Defined in:
lib/ardb/cli/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command_nameObject



70
# File 'lib/ardb/cli/commands.rb', line 70

def self.command_name;    "connect";                      end

.command_summaryObject



71
# File 'lib/ardb/cli/commands.rb', line 71

def self.command_summary; "Connect to the configured DB"; end

Instance Method Details

#run(argv, *args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ardb/cli/commands.rb', line 73

def run(argv, *args)
  super

  begin
    Ardb.init(false)
    Ardb.adapter.connect_db
    @stdout.puts "connected to #{Ardb.config.adapter} db #{Ardb.config.database.inspect}"
  rescue ActiveRecord::NoDatabaseError => e
    @stderr.puts "error: database #{Ardb.config.database.inspect} "\
                 "does not exist"
  rescue StandardError => e
    @stderr.puts e
    @stderr.puts e.backtrace.join("\n")
    @stderr.puts "error connecting to #{Ardb.config.database.inspect} database " \
                 "with #{Ardb.config.activerecord_connect_hash.inspect}"
    raise CommandExitError
  end
end