Class: Brant::MigrationFile
- Inherits:
-
Object
- Object
- Brant::MigrationFile
- Defined in:
- lib/brant/migration_file.rb
Overview
Representation of the actual file that stores a migration
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.all ⇒ Object
Returns hash of migration file objects of all defnied migrations with their timestamps as the keys.
-
.existing ⇒ Object
Returns a hash of migration timestamps that have been performed.
-
.update(migrations) ⇒ Object
Update migrations config to show all finished migrations.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare objects based on timestamp.
-
#initialize(filename) ⇒ MigrationFile
constructor
Constructor logic.
Constructor Details
#initialize(filename) ⇒ MigrationFile
Constructor logic
60 61 62 63 64 65 66 |
# File 'lib/brant/migration_file.rb', line 60 def initialize(filename) self.filename = filename parts = self.filename.split('_') self. = parts.last.split('.').first self.klass = parts[0..-2].join('_').camelize end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
7 8 9 |
# File 'lib/brant/migration_file.rb', line 7 def filename @filename end |
#klass ⇒ Object
Returns the value of attribute klass.
7 8 9 |
# File 'lib/brant/migration_file.rb', line 7 def klass @klass end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/brant/migration_file.rb', line 7 def @timestamp end |
Class Method Details
.all ⇒ Object
Returns hash of migration file objects of all defnied migrations with their timestamps as the keys
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/brant/migration_file.rb', line 12 def self.all migrations = {} if File.exists? Brant.migrationsPath Dir.entries(Brant.migrationsPath).each do |file| next if file.length < 3 || file.match(/^\./) migration = new(file) migrations[migration.] = migration end end migrations end |
.existing ⇒ Object
Returns a hash of migration timestamps that have been performed
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brant/migration_file.rb', line 29 def self.existing migrations = {} if File.exists? Brant.migrationsConfigPath File.open(Brant.migrationsConfigPath,'r') do |file| while(line = file.gets) migrations[line.chomp] = true end end end migrations end |
.update(migrations) ⇒ Object
Update migrations config to show all finished migrations
45 46 47 48 49 |
# File 'lib/brant/migration_file.rb', line 45 def self.update(migrations) File.open(Brant.migrationsConfigPath,'w') do |file| file.write migrations.join("\n") end end |
Instance Method Details
#<=>(other) ⇒ Object
Compare objects based on timestamp
54 55 56 |
# File 'lib/brant/migration_file.rb', line 54 def <=>(other) self. <=> other. end |