class Ponytail::Migration
Attributes
filename[RW]
name[RW]
raw_content[RW]
version[RW]
Public Class Methods
all()
click to toggle source
# File lib/ponytail/migration.rb, line 10 def all proxys = ActiveRecord::Migrator.migrations(migrations_paths) proxys.map { |p| new(name: p.name, filename: p.filename, version: p.version) } end
create(attrs)
click to toggle source
# File lib/ponytail/migration.rb, line 21 def create(attrs) migration = new(attrs) migration.save migration end
find(id)
click to toggle source
# File lib/ponytail/migration.rb, line 27 def find(id) all.select { |x| x.version == id }.first end
next_version()
click to toggle source
# File lib/ponytail/migration.rb, line 16 def next_version last = all.last ActiveRecord::Migration.next_migration_number(last ? last.version + 1 : 0).to_i end
Public Instance Methods
as_json(attrs)
click to toggle source
# File lib/ponytail/migration.rb, line 63 def as_json(attrs) { name: name, filename: filename, version: version, raw_content: raw_content } end
current?()
click to toggle source
# File lib/ponytail/migration.rb, line 59 def current? version == Migration.current_version end
destroy()
click to toggle source
# File lib/ponytail/migration.rb, line 51 def destroy if Ponytail.config.delete_migration? File.delete(filename) else false end end
filename_only()
click to toggle source
# File lib/ponytail/migration.rb, line 32 def filename_only # TODO, WIP: filename.sub("#{Ponytail::Migration.migrations_path}/", "") end
save()
click to toggle source
# File lib/ponytail/migration.rb, line 41 def save if valid? && Ponytail.config.create_migration? 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