Module: Ronin::DB::CLI::DatabaseOptions Private

Includes:
URIMethods
Included in:
Commands::Irb, Commands::Migrate, ModelCommand
Defined in:
lib/ronin/db/cli/database_options.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Base class for all commands that access the database.

Since:

  • 0.2.0

Constant Summary

Constants included from URIMethods

URIMethods::ADAPTER_ALIASES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from URIMethods

#normalize_adapter, #normalize_sqlite3_path, #parse_uri

Class Method Details

.included(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds the --db, --db-uri, and --db-file options to the command class including the Ronin::DB::CLI::DatabaseOptions module.

Parameters:

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ronin/db/cli/database_options.rb', line 42

def self.included(command)
  command.option :db, value: {
                        type:    DB.config.keys,
                        default: :default,
                        usage:   'NAME'
                      },
                      desc: 'The database to connect to'

  command.option :db_uri, value: {
                            type:  String,
                            usage: 'URI'
                          },
                          desc: 'The database URI to connect to'

  command.option :db_file, value: {
                             type:  String,
                             usage: 'PATH'
                           },
                           desc: 'The sqlite3 database file to use'
end

Instance Method Details

#db_configHash{Symbol => String,Integer}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The database connection configuration.

Returns:

  • (Hash{Symbol => String,Integer})

Since:

  • 0.2.0



68
69
70
71
72
73
74
75
76
# File 'lib/ronin/db/cli/database_options.rb', line 68

def db_config
  if options[:db_file]
    {sqlite3: normalize_sqlite3_path(options[:db_file])}
  elsif options[:db_uri]
    parse_uri(options[:db_uri])
  else
    DB.config[options[:db]]
  end
end

#db_connectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Connects to the database.

Since:

  • 0.2.0



81
82
83
# File 'lib/ronin/db/cli/database_options.rb', line 81

def db_connect
  DB.connect(db_config)
end