Sha256: 0e9c60e4b375001c4bf4c530f744b4fd2c4706971a1b22b357e9c9c1d0161dc3
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
class Migration def self.run_migrations(site) Yodel.config.logger.info "Migrating #{site.name}" each_migration_for(site) do |migration, file| unless migration.nil? next if site.migrations.include?(migration.name) migration.up(site) # newly created models are incomplete; reload the site # to force complete versions to be generated for use site.migrations << migration.name site.save site.reload Yodel.config.logger.info "Migrated #{migration.name}" else raise MissingMigration.new(file) end end Yodel.config.logger.info "Migrations for #{site.name} complete" end # As migration files are require'd this method will be triggered so # we have a reference to the 'current' migration class being run def self.inherited(child) @migration = child end private def self.each_migration_for(site, &block) each_migration(File.join(site.migrations_directory, Yodel::YODEL_MIGRATIONS_DIRECTORY_NAME), &block) each_migration(File.join(site.migrations_directory, Yodel::EXTENSION_MIGRATIONS_DIRECTORY_NAME), &block) each_migration(File.join(site.migrations_directory, Yodel::SITE_MIGRATIONS_DIRECTORY_NAME), &block) end # Iterate over every migration and yield the migration class # to the supplied block. Incorrect migration files may result # in nil being yielded. The caller can respond appropriately. # The current file (a string path) is also provided. def self.each_migration(directory) return unless File.directory?(directory) Dir[File.join(directory, '**/*.rb')].sort.each do |file| @migration = nil load file yield @migration, file Object.send(:remove_const, @migration.name.to_sym) if @migration end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
yodel-0.0.3 | lib/yodel/models/core/site/migration.rb |
yodel-0.0.2 | lib/yodel/models/core/site/migration.rb |
yodel-0.0.1 | lib/yodel/models/core/site/migration.rb |