class MigrationBundler::Project

Attributes

config[RW]
database_url[RW]
name[RW]
targets[RW]

Public Class Methods

clear() click to toggle source
# File lib/migration_bundler/project.rb, line 20
def clear
  @project = nil
end
load(path = Dir.pwd) click to toggle source
# File lib/migration_bundler/project.rb, line 7
def load(path = Dir.pwd)
  @project ||= proc do
    project_path = File.join(path, '.migration_bundler.yml')
    raise "fatal: Not a migration_bundler repository: no .migration_bundler.yml" unless File.exists?(project_path)
    options = YAML.load(File.read(project_path))
    new(options)
  end.call
end
new(options = {}) click to toggle source
# File lib/migration_bundler/project.rb, line 27
def initialize(options = {})
  options.each { |k,v| send("#{k}=", v) }
end
set(options) click to toggle source
# File lib/migration_bundler/project.rb, line 16
def set(options)
  @project = new(options)
end

Public Instance Methods

database() click to toggle source
# File lib/migration_bundler/project.rb, line 35
def database
  database_url.scheme || 'sqlite'
end
database_class() click to toggle source
# File lib/migration_bundler/project.rb, line 79
def database_class
  MigrationBundler::Util.database_named(database)
end
database_target_class() click to toggle source
# File lib/migration_bundler/project.rb, line 83
def database_target_class
  MigrationBundler::Util.target_classes_named(database)[0]
end
database_url=(database_url) click to toggle source
# File lib/migration_bundler/project.rb, line 31
def database_url=(database_url)
  @database_url = database_url ? URI(database_url) : nil
end
git_current_branch() click to toggle source
# File lib/migration_bundler/project.rb, line 55
def git_current_branch
  `git symbolic-ref --short HEAD`.chomp
end
git_latest_tag() click to toggle source
# File lib/migration_bundler/project.rb, line 51
def git_latest_tag
  git_tag_for_version(nil)
end
git_tag_for_version(version) click to toggle source
# File lib/migration_bundler/project.rb, line 59
def git_tag_for_version(version)
  pattern = version && "#{version}*"
  tag = `git tag -l --sort=-v:refname #{pattern} | head -n 1`.chomp
  raise "Failed trying to determine version tag: Git may be outdated. Git >= 1.9.0 is required." unless $?.exitstatus.zero?
  tag.empty? ? nil : tag
end
git_url() click to toggle source
# File lib/migration_bundler/project.rb, line 47
def git_url
  `git config remote.origin.url`.chomp
end
git_user_email() click to toggle source
# File lib/migration_bundler/project.rb, line 66
def git_user_email
  `git config user.email`.chomp
end
git_user_name() click to toggle source
# File lib/migration_bundler/project.rb, line 70
def git_user_name
  `git config user.name`.chomp
end
migrations_path() click to toggle source
# File lib/migration_bundler/project.rb, line 43
def migrations_path
  "migrations"
end
save!(path) click to toggle source
# File lib/migration_bundler/project.rb, line 74
def save!(path)
  project_path = File.join(path, '.migration_bundler.yml')
  File.open(project_path, 'w') { |f| f << YAML.dump(self.to_hash) }
end
schema_path() click to toggle source
# File lib/migration_bundler/project.rb, line 39
def schema_path
  "#{name}" + database_class.migration_ext
end
to_hash() click to toggle source
# File lib/migration_bundler/project.rb, line 87
def to_hash
  { "name" => name, "config" => config, "database_url" => database_url.to_s, "targets" => targets }
end