Class: MaglevRecord::MigrationLoader
- Defined in:
- lib/maglev_record/migration/loader.rb
Instance Method Summary collapse
-
#initialize ⇒ MigrationLoader
constructor
A new instance of MigrationLoader.
- #load_directory(directory_path) ⇒ Object
- #load_file(file_path) ⇒ Object
- #load_string(source, file = __FILE__) ⇒ Object
- #migration_list ⇒ Object
Constructor Details
#initialize ⇒ MigrationLoader
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
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_list ⇒ Object
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 |