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
14 15 16 17 |
# File 'lib/ponytail/migration.rb', line 14 def all proxys = ActiveRecord::Migrator.migrations(migrations_paths) proxys.map { |p| new(name: p.name, filename: p.filename, version: p.version) } end |
.check_pending? ⇒ Boolean
10 11 12 |
# File 'lib/ponytail/migration.rb', line 10 def check_pending? ActiveRecord::VERSION::MAJOR >= 4 && Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending) end |
.migrate ⇒ Object
20 21 22 |
# File 'lib/ponytail/migration.rb', line 20 def migrate ActiveRecord::Migrator.migrate(migrations_paths) end |
.next_version ⇒ Object
28 29 30 31 |
# File 'lib/ponytail/migration.rb', line 28 def next_version last = all.last ActiveRecord::Migration.next_migration_number(last ? last.version + 1 : 0).to_i end |
.rollback ⇒ Object
24 25 26 |
# File 'lib/ponytail/migration.rb', line 24 def rollback ActiveRecord::Migrator.rollback(migrations_paths) end |
Instance Method Details
#destroy ⇒ Object
48 49 50 |
# File 'lib/ponytail/migration.rb', line 48 def destroy File.delete(filename) end |
#save ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ponytail/migration.rb', line 38 def save if valid? next_filename = "#{Migration.migrations_path}/#{Migration.next_version}_#{name.underscore}.rb" open(next_filename, 'w') { |f| f.write(raw_content) } true else false end end |