Class: Migr8::Actions::Action

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

Constant Summary collapse

NAME =
nil
DESC =
nil
OPTS =
[]
ARGS =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object



1404
1405
1406
# File 'lib/migr8.rb', line 1404

def self.find_by_name(name)
  return @subclasses.find {|cls| cls.const_get(:NAME) == name }
end

.inherited(subclass) ⇒ Object



1396
1397
1398
# File 'lib/migr8.rb', line 1396

def self.inherited(subclass)
  @subclasses << subclass
end

.subclassesObject



1400
1401
1402
# File 'lib/migr8.rb', line 1400

def self.subclasses
  @subclasses
end

Instance Method Details

#cmdopterr(*args) ⇒ Object



1328
1329
1330
# File 'lib/migr8.rb', line 1328

def cmdopterr(*args)
  return Util::CommandOptionError.new(*args)
end

#get_commandObject



1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
# File 'lib/migr8.rb', line 1332

def get_command
  cmd = ENV['MIGR8_COMMAND'] || ''
  ! cmd.empty?  or
    raise CommandSetupError.new(<<END)
##
## ERROR: $MIGR8_COMMAND is empty. Please set it at first.
## Example: (MacOSX, Unix)
##     $ export MIGR8_COMMAND='sqlite3 dbname'           # for SQLite3
##                       # or 'psql -q -U user dbname'   # for PosgreSQL
##                       # or 'mysql -s -u user dbname'  # for MySQL
## Example: (Windows)
##     C:\\> set MIGR8_COMMAND='sqlite3 dbname'           # for SQLite3
##                       # or 'psql -q -U user dbname'   # for PostgreSQL
##                       # or 'mysql -s -u user dbname'  # for MySQL
##
## Run '#{File.basename($0)} readme' for details.
##
END
  return cmd
end

#parse(args) ⇒ Object



1301
1302
1303
# File 'lib/migr8.rb', line 1301

def parse(args)
  return parser().parse(args)
end

#parserObject



1292
1293
1294
1295
1296
1297
1298
1299
# File 'lib/migr8.rb', line 1292

def parser
  name = self.class.const_get(:NAME)
  opts = self.class.const_get(:OPTS)
  parser = Util::CommandOptionParser.new("#{name}:")
  parser.add("-h, --help:")
  opts.each {|cmdopt| parser.add(cmdopt) }
  return parser
end

#repository(dbms = nil) ⇒ Object



1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
# File 'lib/migr8.rb', line 1353

def repository(dbms=nil)
  return @repository || begin
                          cmd = get_command()
                          dbms = DBMS.detect_by_command(cmd)
                          $MIGR8_DBMS = dbms     # TODO: remove if possible
                          repo = Repository.new(dbms)
                          _check(repo, dbms) if _should_check?
                          repo
                        end
end

#run(options, args) ⇒ Object

Raises:

  • (NotImplementedError)


1324
1325
1326
# File 'lib/migr8.rb', line 1324

def run(options, args)
  raise NotImplementedError.new("#{self.class.name}#run(): not implemented yet.")
end

#short_usageObject



1315
1316
1317
1318
1319
1320
1321
1322
# File 'lib/migr8.rb', line 1315

def short_usage()
  klass = self.class
  name = klass.const_get(:NAME)
  args = klass.const_get(:ARGS)
  desc = klass.const_get(:DESC)
  s = args ? "#{name} #{args}" : "#{name}"
  return "  %-20s: %s\n" % [s, desc]
end

#usageObject



1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/migr8.rb', line 1305

def usage
  klass = self.class
  name = klass.const_get(:NAME)
  args = klass.const_get(:ARGS)
  desc = klass.const_get(:DESC)
  s = args ? "#{name} #{args}" : "#{name}"
  head = "#{File.basename($0)} #{s}  : #{desc}\n"
  return head+parser().usage(20, '  ')
end