Class: Ardb::Runner
- Inherits:
-
Object
- Object
- Ardb::Runner
- 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
-
#cmd_args ⇒ Object
readonly
Returns the value of attribute cmd_args.
-
#cmd_name ⇒ Object
readonly
Returns the value of attribute cmd_name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(args, opts) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
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_args ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute cmd_name.
9 10 11 |
# File 'lib/ardb/runner.rb', line 9 def cmd_name @cmd_name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
9 10 11 |
# File 'lib/ardb/runner.rb', line 9 def opts @opts end |
Instance Method Details
#run ⇒ Object
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 |