class Kafo::Migrations
Attributes
Public Class Methods
Source
# File lib/kafo/migrations.rb, line 9 def initialize(migrations_dir) @migrations_dir = migrations_dir @migrations = {} @applied_file = File.join(@migrations_dir, '.applied') load_migrations end
Public Instance Methods
Source
# File lib/kafo/migrations.rb, line 30 def add_migration(name, &block) @migrations[name] = block end
Source
# File lib/kafo/migrations.rb, line 20 def load_migrations Dir.glob(@migrations_dir + "/*.rb").each do |file| next if applied.include?(File.basename(file)) KafoConfigure.logger.debug "Loading migration #{file}" migration = File.read(file) migration_block = proc { instance_eval(migration, file, 1) } add_migration(file, &migration_block) end end
Source
# File lib/kafo/migrations.rb, line 34 def run(scenario, answers) @migrations.keys.sort.each do |name| KafoConfigure.logger.debug "Executing migration #{name}" migration = @migrations[name] scenario, answers = Kafo::MigrationContext.execute(scenario, answers, &migration) applied << File.basename(name.to_s) end return scenario, answers end
Source
# File lib/kafo/migrations.rb, line 44 def store_applied File.open(@applied_file, 'w') { |f| f.write(applied.to_yaml) } end
Private Instance Methods
Source
# File lib/kafo/migrations.rb, line 50 def load_applied File.exist?(@applied_file) ? YAML.load_file(@applied_file) : [] end