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



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

Returns:

  • (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

.migrateObject



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

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

.next_versionObject



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

.rollbackObject



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

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

Instance Method Details

#destroyObject



48
49
50
# File 'lib/ponytail/migration.rb', line 48

def destroy
  File.delete(filename)
end

#saveObject



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