Class: DataMigrater::Migration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, name, filename, path = "#{Rails.root}/db/data_migrate") ⇒ Migration

Returns a new instance of Migration.



7
8
9
10
11
12
# File 'lib/data_migrater/migration.rb', line 7

def initialize(version, name, filename, path = "#{Rails.root}/db/data_migrate")
  @filename = filename
  @name     = name
  @path     = path
  @version  = version
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/data_migrater/migration.rb', line 5

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/data_migrater/migration.rb', line 5

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/data_migrater/migration.rb', line 5

def version
  @version
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/data_migrater/migration.rb', line 14

def execute
  data_migration = DataMigration.new version: @version

  return false unless data_migration.valid?

  begin
    data_migration.save!
    migration.execute
  rescue StandardError => e
    data_migration.destroy

    raise e
  end
end