Class: Migrate::Controller

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

Constant Summary collapse

ROOT =
Build::Files::Path.current / "migrate"

Instance Method Summary collapse

Constructor Details

#initialize(root = ROOT) ⇒ Controller

Returns a new instance of Controller.



30
31
32
# File 'lib/migrate/controller.rb', line 30

def initialize(root = ROOT)
	@root = root
end

Instance Method Details

#create!(name, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/migrate/controller.rb', line 45

def create!(name, &block)
	prefix = Time.now.strftime("%Y%m%d%H%M%S")
	path = @root / "#{prefix}-#{name}.rb"
	path.parent.mkpath
	
	path.open(File::CREAT|File::TRUNC|File::WRONLY, &block)
	
	return path
end

#migrate!Object



38
39
40
41
42
43
# File 'lib/migrate/controller.rb', line 38

def migrate!
	migrations.each do |migration|
		Console.logger.debug(self, "Applying #{migration}...")
		migration.call(self)
	end
end

#migrationsObject



34
35
36
# File 'lib/migrate/controller.rb', line 34

def migrations
	@root.glob("**/*.rb").map{|path| Migration.new(path)}.sort
end