Class: MigrationBundler::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/migration_bundler/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Project

Returns a new instance of Project.



27
28
29
# File 'lib/migration_bundler/project.rb', line 27

def initialize(options = {})
  options.each { |k,v| send("#{k}=", v) }
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



25
26
27
# File 'lib/migration_bundler/project.rb', line 25

def config
  @config
end

#database_urlObject

Returns the value of attribute database_url.



25
26
27
# File 'lib/migration_bundler/project.rb', line 25

def database_url
  @database_url
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/migration_bundler/project.rb', line 25

def name
  @name
end

#targetsObject

Returns the value of attribute targets.



25
26
27
# File 'lib/migration_bundler/project.rb', line 25

def targets
  @targets
end

Class Method Details

.clearObject



20
21
22
# File 'lib/migration_bundler/project.rb', line 20

def clear
  @project = nil
end

.load(path = Dir.pwd) ⇒ Object



7
8
9
10
11
12
13
14
# 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

.set(options) ⇒ Object



16
17
18
# File 'lib/migration_bundler/project.rb', line 16

def set(options)
  @project = new(options)
end

Instance Method Details

#databaseObject



35
36
37
# File 'lib/migration_bundler/project.rb', line 35

def database
  database_url.scheme || 'sqlite'
end

#database_classObject



79
80
81
# File 'lib/migration_bundler/project.rb', line 79

def database_class
  MigrationBundler::Util.database_named(database)
end

#database_target_classObject



83
84
85
# File 'lib/migration_bundler/project.rb', line 83

def database_target_class
  MigrationBundler::Util.target_classes_named(database)[0]
end

#git_current_branchObject



55
56
57
# File 'lib/migration_bundler/project.rb', line 55

def git_current_branch
  `git symbolic-ref --short HEAD`.chomp
end

#git_latest_tagObject



51
52
53
# File 'lib/migration_bundler/project.rb', line 51

def git_latest_tag
  git_tag_for_version(nil)
end

#git_tag_for_version(version) ⇒ Object



59
60
61
62
63
64
# 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_urlObject



47
48
49
# File 'lib/migration_bundler/project.rb', line 47

def git_url
  `git config remote.origin.url`.chomp
end

#git_user_emailObject



66
67
68
# File 'lib/migration_bundler/project.rb', line 66

def git_user_email
  `git config user.email`.chomp
end

#git_user_nameObject



70
71
72
# File 'lib/migration_bundler/project.rb', line 70

def git_user_name
  `git config user.name`.chomp
end

#migrations_pathObject



43
44
45
# File 'lib/migration_bundler/project.rb', line 43

def migrations_path
  "migrations"
end

#save!(path) ⇒ Object



74
75
76
77
# 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_pathObject



39
40
41
# File 'lib/migration_bundler/project.rb', line 39

def schema_path
  "#{name}" + database_class.migration_ext
end

#to_hashObject



87
88
89
# File 'lib/migration_bundler/project.rb', line 87

def to_hash
  { "name" => name, "config" => config, "database_url" => database_url.to_s, "targets" => targets }
end