Class: Binder::Migrate
Overview
Public: [Command] Runs your migrations. Used via the ‘arb` command.
Instance Method Summary
collapse
Methods inherited from Strategy
alias_class, #justify_size, #merge_options_aliases
Instance Method Details
#_require_path(path) ⇒ Object
52
|
# File 'lib/cli/commands/migrate.rb', line 52
def _require_path path; "Requiring #{path.colorize(:green)}: #{require(path).to_s.colorize(:orange)}" end
|
#description ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/cli/commands/migrate.rb', line 62
def description
indent = ' ' * (justify_size * 2)
str = []
str << "Migrate to the specified version"
str << "#{indent}" + "-v".colorize(:rose) + ", --version".colorize(:rose) + ", --to".colorize(:rose) + " - Version we want to migrate to"
str << "#{indent}" + "-d".colorize(:rose) + ", --directory".colorize(:rose) + " - Allow to specify a set of directories holding your migrations"
str << "#{indent}" + "-r".colorize(:rose) + ", --recursive".colorize(:rose) + " - Same as `--directory` but will search recursively in the directories"
str << "#{indent}" + "-f".colorize(:rose) + ", --file".colorize(:rose) + " - Allow to specify a set of files holding your migrations"
str << "#{indent}" + "-a".colorize(:rose) + ", --adapter".colorize(:rose) + ", --plug".colorize(:rose) + " - Specify a Binder class on which to run the migration"
str.join("\n")
end
|
#directory(blobs, recursively = false) ⇒ Object
Also known as:
d, file, f
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/cli/commands/migrate.rb', line 33
def directory blobs, recursively = false
blobs.each do |blob|
blob = File::absolute_path(blob)
raise CommandParser::ParseError.new("Invalid argument : no such file or directory #{blob}.") unless File::exists?(blob)
if File::directory?(blob)
files = Dir.glob("#{blob}/*")
files.each do |file|
if recursively == true && File::directory?(file)
directory [file], true
end
puts _require_path(file) unless File::directory?(file)
end
else
puts _require_path(blob)
end
end
end
|
#execute(args) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/cli/commands/migrate.rb', line 6
def execute args
commands = CommandParser::parse_options(args)
commands.each do |c|
option = c[:option]
args = c[:options_args]
self.send(option.to_sym, args)
end
"\nDone."
end
|
#plug(args) ⇒ Object
Also known as:
a, adapter, adaptor
23
24
25
26
27
28
|
# File 'lib/cli/commands/migrate.rb', line 23
def plug args
args.each do |klass|
raise MigrationProcessError.new("Plug #{klass.colorize(:red)} not found.") unless Object.const_defined?(klass)
Object.const_get(klass).migrate @version
end
end
|
#recursive(blobs) ⇒ Object
Also known as:
r
57
58
59
|
# File 'lib/cli/commands/migrate.rb', line 57
def recursive blobs
directory blobs, true
end
|
#version(version) ⇒ Object
Also known as:
v, to
16
17
18
19
|
# File 'lib/cli/commands/migrate.rb', line 16
def version version
puts "Migrating toward version #{version.first.to_f.to_s.colorize(:orange)}"
@version ||= version.first.to_f
end
|