Class: MigrationBundler::Project
- Inherits:
-
Object
- Object
- MigrationBundler::Project
- Defined in:
- lib/migration_bundler/project.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#database_url ⇒ Object
Returns the value of attribute database_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#targets ⇒ Object
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
- #database ⇒ Object
- #database_class ⇒ Object
- #database_target_class ⇒ Object
- #git_current_branch ⇒ Object
- #git_latest_tag ⇒ Object
- #git_tag_for_version(version) ⇒ Object
- #git_url ⇒ Object
- #git_user_email ⇒ Object
- #git_user_name ⇒ Object
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
- #migrations_path ⇒ Object
- #save!(path) ⇒ Object
- #schema_path ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
27 28 29 |
# File 'lib/migration_bundler/project.rb', line 27 def initialize( = {}) .each { |k,v| send("#{k}=", v) } end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
25 26 27 |
# File 'lib/migration_bundler/project.rb', line 25 def config @config end |
#database_url ⇒ Object
Returns the value of attribute database_url.
25 26 27 |
# File 'lib/migration_bundler/project.rb', line 25 def database_url @database_url end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/migration_bundler/project.rb', line 25 def name @name end |
#targets ⇒ Object
Returns the value of attribute targets.
25 26 27 |
# File 'lib/migration_bundler/project.rb', line 25 def targets @targets end |
Class Method Details
.clear ⇒ Object
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) = YAML.load(File.read(project_path)) new() end.call end |
.set(options) ⇒ Object
16 17 18 |
# File 'lib/migration_bundler/project.rb', line 16 def set() @project = new() end |
Instance Method Details
#database ⇒ Object
35 36 37 |
# File 'lib/migration_bundler/project.rb', line 35 def database database_url.scheme || 'sqlite' end |
#database_class ⇒ Object
79 80 81 |
# File 'lib/migration_bundler/project.rb', line 79 def database_class MigrationBundler::Util.database_named(database) end |
#database_target_class ⇒ Object
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_branch ⇒ Object
55 56 57 |
# File 'lib/migration_bundler/project.rb', line 55 def git_current_branch `git symbolic-ref --short HEAD`.chomp end |
#git_latest_tag ⇒ Object
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_url ⇒ Object
47 48 49 |
# File 'lib/migration_bundler/project.rb', line 47 def git_url `git config remote.origin.url`.chomp end |
#git_user_email ⇒ Object
66 67 68 |
# File 'lib/migration_bundler/project.rb', line 66 def git_user_email `git config user.email`.chomp end |
#git_user_name ⇒ Object
70 71 72 |
# File 'lib/migration_bundler/project.rb', line 70 def git_user_name `git config user.name`.chomp end |
#migrations_path ⇒ Object
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_path ⇒ Object
39 40 41 |
# File 'lib/migration_bundler/project.rb', line 39 def schema_path "#{name}" + database_class.migration_ext end |
#to_hash ⇒ Object
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 |