Class: Ponytail::Migration

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/ponytail/migration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#raw_contentObject

Returns the value of attribute raw_content.



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

def raw_content
  @raw_content
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.allObject



7
8
9
10
# File 'lib/ponytail/migration.rb', line 7

def all
  proxys = ActiveRecord::Migrator.migrations(migrations_paths)
  proxys.map { |p| new(name: p.name, filename: p.filename, version: p.version) }
end

.migrateObject



13
14
15
# File 'lib/ponytail/migration.rb', line 13

def migrate
  ActiveRecord::Migrator.migrate(migrations_paths)
end

.next_versionObject



21
22
23
24
# File 'lib/ponytail/migration.rb', line 21

def next_version
  last = all.last
  ActiveRecord::Migration.next_migration_number(last ? last.version + 1 : 0).to_i
end

.rollbackObject



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

def rollback
  ActiveRecord::Migrator.rollback(migrations_paths)
end

Instance Method Details

#saveObject



31
32
33
34
35
36
37
38
# File 'lib/ponytail/migration.rb', line 31

def save
  if valid?
    next_migration_filename = "#{Migration.migrations_path}/#{Migration.next_version}_#{name.underscore}.rb"
    open(next_migration_filename, 'w').write(raw_content)
  else
    false
  end
end