Class: JewelSeed::MigrationProxy
- Inherits:
-
Object
- Object
- JewelSeed::MigrationProxy
- Defined in:
- lib/jewel_seed/migration_proxy.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #down ⇒ Object
-
#initialize(file_name) ⇒ MigrationProxy
constructor
A new instance of MigrationProxy.
- #load_migration ⇒ Object
- #migration ⇒ Object
- #migration_class ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(file_name) ⇒ MigrationProxy
Returns a new instance of MigrationProxy.
5 6 7 8 9 10 |
# File 'lib/jewel_seed/migration_proxy.rb', line 5 def initialize(file_name) @file_name = file_name version, name = @file_name.scan(/([0-9]+)_([_a-z0-9]*)\.rb/).first @version = version.to_i @name = name.camelize end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/jewel_seed/migration_proxy.rb', line 3 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/jewel_seed/migration_proxy.rb', line 3 def version @version end |
Instance Method Details
#down ⇒ Object
22 23 24 25 26 27 |
# File 'lib/jewel_seed/migration_proxy.rb', line 22 def down migration.down seed_migration = SeedMigration.find_by(version: version) seed_migration.destroy end |
#load_migration ⇒ Object
37 38 39 40 |
# File 'lib/jewel_seed/migration_proxy.rb', line 37 def load_migration require(File.(@file_name)) migration_class.new end |
#migration ⇒ Object
33 34 35 |
# File 'lib/jewel_seed/migration_proxy.rb', line 33 def migration @migration ||= load_migration end |
#migration_class ⇒ Object
29 30 31 |
# File 'lib/jewel_seed/migration_proxy.rb', line 29 def migration_class name.constantize end |
#up ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/jewel_seed/migration_proxy.rb', line 12 def up migration.up seed_migration = SeedMigration.create!(version: version) seed_migration_tables = migration.table_names.map do |t| SeedMigrationTable.new(seed_migration: seed_migration, table_name: t) end SeedMigrationTable.import(seed_migration_tables) end |