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



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

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

Returns:

  • (Boolean)


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

def check_pending?
  Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending)
end

.migrateObject



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

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

.next_versionObject



25
26
27
28
# File 'lib/ponytail/migration.rb', line 25

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

.rollbackObject



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

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

Instance Method Details

#saveObject



35
36
37
38
39
40
41
42
# File 'lib/ponytail/migration.rb', line 35

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