Class: Ponytail::Migration
- Inherits:
-
Object
- Object
- Ponytail::Migration
- Includes:
- ActiveModel::Model
- Defined in:
- lib/ponytail/migration.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_content ⇒ Object
Returns the value of attribute raw_content.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/ponytail/migration.rb', line 4 def filename @filename end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/ponytail/migration.rb', line 4 def name @name end |
#raw_content ⇒ Object
Returns the value of attribute raw_content.
4 5 6 |
# File 'lib/ponytail/migration.rb', line 4 def raw_content @raw_content end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/ponytail/migration.rb', line 4 def version @version end |
Class Method Details
.all ⇒ Object
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 |
.migrate ⇒ Object
13 14 15 |
# File 'lib/ponytail/migration.rb', line 13 def migrate ActiveRecord::Migrator.migrate(migrations_paths) end |
.next_version ⇒ Object
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 |
.rollback ⇒ Object
17 18 19 |
# File 'lib/ponytail/migration.rb', line 17 def rollback ActiveRecord::Migrator.rollback(migrations_paths) end |
Instance Method Details
#save ⇒ Object
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 |