Class: MaglevRecord::MigrationLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/maglev_record/migration/loader.rb

Instance Method Summary collapse

Constructor Details

#initializeMigrationLoader

Returns a new instance of MigrationLoader.



10
11
12
# File 'lib/maglev_record/migration/loader.rb', line 10

def initialize
  @migration_list = []
end

Instance Method Details

#load_directory(directory_path) ⇒ Object



32
33
34
35
36
# File 'lib/maglev_record/migration/loader.rb', line 32

def load_directory(directory_path)
  Dir.foreach(directory_path) { |file_name|
    load_file(directory_path + '/' + file_name) if file_name.end_with? '.rb'
  }
end

#load_file(file_path) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
# File 'lib/maglev_record/migration/loader.rb', line 27

def load_file(file_path)
  raise ArgumentError, "file #{file_path.inspect} not found" unless File.file?(file_path)
  load_string(File.open(file_path).read, file_path)
end

#load_string(source, file = __FILE__) ⇒ Object



20
21
22
23
24
25
# File 'lib/maglev_record/migration/loader.rb', line 20

def load_string(source, file = __FILE__)
  migration = instance_eval source, file
  raise MaglevRecord::NoMigrationReadError unless migration.class == MaglevRecord::Migration
  migration.source = source
  @migration_list << migration
end

#migration_listObject



14
15
16
17
18
# File 'lib/maglev_record/migration/loader.rb', line 14

def migration_list
  # TODO
  # Print a warning, if there are two or more migrations which are equal.
  @migration_list.sort.uniq
end