Class: Ardb::Runner

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

Defined Under Namespace

Classes: ConnectCommand, CreateCommand, DropCommand, GenerateCommand, MigrateCommand, NullCommand

Constant Summary collapse

UnknownCmdError =
Class.new(ArgumentError)
CmdError =
Class.new(RuntimeError)
CmdFail =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, opts) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
# File 'lib/ardb/runner.rb', line 11

def initialize(args, opts)
  @opts = opts
  @cmd_name = args.shift || ""
  @cmd_args = args
end

Instance Attribute Details

#cmd_argsObject (readonly)

Returns the value of attribute cmd_args.



9
10
11
# File 'lib/ardb/runner.rb', line 9

def cmd_args
  @cmd_args
end

#cmd_nameObject (readonly)

Returns the value of attribute cmd_name.



9
10
11
# File 'lib/ardb/runner.rb', line 9

def cmd_name
  @cmd_name
end

#optsObject (readonly)

Returns the value of attribute opts.



9
10
11
# File 'lib/ardb/runner.rb', line 9

def opts
  @opts
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ardb/runner.rb', line 17

def run
  $LOAD_PATH.push(Dir.pwd) unless $LOAD_PATH.include?(Dir.pwd)
  Ardb.init(false) # don't establish a connection

  case @cmd_name
  when 'migrate'
    require 'ardb/runner/migrate_command'
    MigrateCommand.new.run
  when 'generate'
    require 'ardb/runner/generate_command'
    GenerateCommand.new(@cmd_args).run
  when 'create'
    require 'ardb/runner/create_command'
    CreateCommand.new.run
  when 'drop'
    require 'ardb/runner/drop_command'
    DropCommand.new.run
  when 'connect'
    require 'ardb/runner/connect_command'
    ConnectCommand.new.run
  when 'null'
    NullCommand.new.run
  else
    raise UnknownCmdError, "unknown command `#{@cmd_name}`"
  end
end