Class: Ronin::DB::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/ronin/db/tasks.rb

Overview

Defines ronin:db tasks in a Rakefile.

Example

require 'ronin/db/tasks'
Ronin::DB::Tasks.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database: :default) ⇒ Tasks

Initializes the tasks.

Parameters:

  • database (Symbol, Hash) (defaults to: :default)

    The database name or Hash to connect to.



48
49
50
51
52
53
54
# File 'lib/ronin/db/tasks.rb', line 48

def initialize(database: :default)
  super()

  @database = database

  define
end

Instance Attribute Details

#databaseSymbol, Hash (readonly)

The database to connect to.

Returns:

  • (Symbol, Hash)


38
39
40
# File 'lib/ronin/db/tasks.rb', line 38

def database
  @database
end

Instance Method Details

#defineObject

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.

Defines the ronin:db tasks.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ronin/db/tasks.rb', line 61

def define
  namespace :db do
    task :connect do
      require 'ronin/db'
      DB.connect(@database)
    end

    desc 'Migrates the development database'
    task :migrate => :connect do
      require 'ronin/db/migrations'
      DB::Migrations.up
    end

    desc 'Starts an interactive database console'
    task :console => :connect do
      require 'logger'
      DB.logger = Logger.new($stderr,:debug)

      require 'ronin/db/cli/ruby_shell'
      DB::CLI::RubyShell.start
    end
  end
end