Sha256: 4501e83cdf86fe0872634619f104235d32377ab89cdc89a7728c1bcad752a824
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
require 'ardb' module Ardb; end class Ardb::Runner UnknownCmdError = Class.new(ArgumentError) CmdError = Class.new(RuntimeError) CmdFail = Class.new(RuntimeError) attr_reader :cmd_name, :cmd_args, :opts, :root_path def initialize(args, opts) @opts = opts @cmd_name = args.shift || "" @cmd_args = args @root_path = @opts.delete('root_path') || Dir.pwd end def run setup_run 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 'null' NullCommand.new.run else raise UnknownCmdError, "unknown command `#{@cmd_name}`" end end private def setup_run Ardb.config.root_path = @root_path DbConfigFile.new.require_if_exists Ardb.init(false) # don't establish a connection end class DbConfigFile PATH = 'config/db.rb' def initialize @path = Ardb.config.root_path.join(PATH) end def require_if_exists require @path.to_s if File.exists?(@path.to_s) end end class NullCommand def run # if this was a real command it would do something here end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ardb-0.2.0 | lib/ardb/runner.rb |
ardb-0.1.0 | lib/ardb/runner.rb |