Class: Paresseux::Migration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, version) ⇒ Migration

Returns a new instance of Migration.



6
7
8
# File 'lib/paresseux/migration.rb', line 6

def initialize(model, version)
  @model, @version, @current_version = model, version, model.paresseux_version
end

Instance Attribute Details

#current_versionObject (readonly)

Returns the value of attribute current_version.



4
5
6
# File 'lib/paresseux/migration.rb', line 4

def current_version
  @current_version
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/paresseux/migration.rb', line 4

def model
  @model
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/paresseux/migration.rb', line 4

def version
  @version
end

Instance Method Details

#migrateObject



10
11
12
13
14
# File 'lib/paresseux/migration.rb', line 10

def migrate
  (current_version...version).each do |index|
    send("migration_#{index}_to_#{index + 1}")
  end
end

#migrate!Object



16
17
18
19
# File 'lib/paresseux/migration.rb', line 16

def migrate!
  migrate
  model.save
end