Class: Migr8::Actions::Action
- Inherits:
-
Object
- Object
- Migr8::Actions::Action
show all
- Defined in:
- lib/migr8.rb
Direct Known Subclasses
ApplyAction, DeleteAction, DownAction, EditAction, HelpAction, HistAction, InitAction, NewAction, ReadMeAction, RedoAction, ShowAction, StatusAction, UnapplyAction, UpAction
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
1402
1403
1404
|
# File 'lib/migr8.rb', line 1402
def self.find_by_name(name)
return @subclasses.find {|cls| cls.const_get(:NAME) == name }
end
|
.inherited(subclass) ⇒ Object
1394
1395
1396
|
# File 'lib/migr8.rb', line 1394
def self.inherited(subclass)
@subclasses << subclass
end
|
.subclasses ⇒ Object
1398
1399
1400
|
# File 'lib/migr8.rb', line 1398
def self.subclasses
@subclasses
end
|
Instance Method Details
#cmdopterr(*args) ⇒ Object
1326
1327
1328
|
# File 'lib/migr8.rb', line 1326
def cmdopterr(*args)
return Util::CommandOptionError.new(*args)
end
|
#get_command ⇒ Object
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
|
# File 'lib/migr8.rb', line 1330
def get_command
cmd = ENV['MIGR8_COMMAND'] || ''
! cmd.empty? or
raise CommandSetupError.new("##\n## ERROR: $MIGR8_COMMAND is empty. Please set it at first.\n## Example: (MacOSX, Unix)\n## $ export MIGR8_COMMAND='sqlite3 dbname' # for SQLite3\n## # or 'psql -q -U user dbname' # for PosgreSQL\n## # or 'mysql -s -u user dbname' # for MySQL\n## Example: (Windows)\n## C:\\\\> set MIGR8_COMMAND='sqlite3 dbname' # for SQLite3\n## # or 'psql -q -U user dbname' # for PostgreSQL\n## # or 'mysql -s -u user dbname' # for MySQL\n##\n## Run '\#{File.basename($0)} readme' for details.\n##\n")
return cmd
end
|
#parse(args) ⇒ Object
1299
1300
1301
|
# File 'lib/migr8.rb', line 1299
def parse(args)
return parser().parse(args)
end
|
#parser ⇒ Object
1290
1291
1292
1293
1294
1295
1296
1297
|
# File 'lib/migr8.rb', line 1290
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
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
|
# File 'lib/migr8.rb', line 1351
def repository(dbms=nil)
return @repository || begin
cmd = get_command()
dbms = DBMS.detect_by_command(cmd)
$MIGR8_DBMS = dbms
repo = Repository.new(dbms)
_check(repo, dbms) if _should_check?
repo
end
end
|
#run(options, args) ⇒ Object
1322
1323
1324
|
# File 'lib/migr8.rb', line 1322
def run(options, args)
raise NotImplementedError.new("#{self.class.name}#run(): not implemented yet.")
end
|
#short_usage ⇒ Object
1313
1314
1315
1316
1317
1318
1319
1320
|
# File 'lib/migr8.rb', line 1313
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
|
#usage ⇒ Object
1303
1304
1305
1306
1307
1308
1309
1310
1311
|
# File 'lib/migr8.rb', line 1303
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
|