class DbToFile::VersionController

Constants

DEFAULT_COMMIT_MESSAGE

Public Instance Methods

get_modified_file_list() click to toggle source
# File lib/db_to_file/version_controller.rb, line 23
def get_modified_file_list
  modified_files
end
merge_conflicts_present?() click to toggle source
# File lib/db_to_file/version_controller.rb, line 18
def merge_conflicts_present?
  out = SystemExecuter.new('git status --porcelain').execute.split("\n")
  out.any?{|line| line[0..0] == 'U'}
end
prepare_code_version() click to toggle source
# File lib/db_to_file/version_controller.rb, line 3
def prepare_code_version
  SystemExecuter.new("git stash save 'db-to-file'").execute
  SystemExecuter.new('git pull').execute
  FileUtils.rm_rf('db/db_to_file')
end
restore_local_stash() click to toggle source
# File lib/db_to_file/version_controller.rb, line 14
def restore_local_stash
  restore_stash
end
update_code_version(commit_message = nil) click to toggle source
# File lib/db_to_file/version_controller.rb, line 9
def update_code_version(commit_message = nil)
  update_commit_stash
  commit_changes(commit_message) if commitable_files_present?
end

Private Instance Methods

commit_changes(commit_message) click to toggle source
# File lib/db_to_file/version_controller.rb, line 48
def commit_changes(commit_message)
  puts 'Commit changes'
  message = commit_message || DEFAULT_COMMIT_MESSAGE
  git.commit(message)
end
commitable_files_present?() click to toggle source
# File lib/db_to_file/version_controller.rb, line 43
def commitable_files_present?
  out = SystemExecuter.new('git status --porcelain').execute
  out.split("\n").reject{|line| [' ', '?'].include?(line[0])}.any?
end
deleted_files() click to toggle source
# File lib/db_to_file/version_controller.rb, line 66
def deleted_files
  git.status.deleted.map{|file, git_object| file}
end
git() click to toggle source
# File lib/db_to_file/version_controller.rb, line 74
def git
  @git ||= Git.open(Dir.pwd)
end
modified_files() click to toggle source
# File lib/db_to_file/version_controller.rb, line 62
def modified_files
  git.status.changed.map{|file, git_object| file}
end
new_files() click to toggle source
# File lib/db_to_file/version_controller.rb, line 58
def new_files
  git.status.untracked.map{|file, git_object| file}
end
restore_stash() click to toggle source
# File lib/db_to_file/version_controller.rb, line 54
def restore_stash
  SystemExecuter.new('git stash pop').execute
end
table_file?(file) click to toggle source
# File lib/db_to_file/version_controller.rb, line 70
def table_file?(file)
  file.index('db/db_to_file') === 0
end
update_commit_stash() click to toggle source
# File lib/db_to_file/version_controller.rb, line 30
def update_commit_stash
  SystemExecuter.new('git status --porcelain').execute
  new_files.each do |file|
    SystemExecuter.new("git add #{file}").execute if table_file?(file)
  end
  modified_files.each do |file|
    SystemExecuter.new("git add #{file}").execute if table_file?(file)
  end
  deleted_files.each do |file|
    SystemExecuter.new("git rm #{file}").execute if table_file?(file)
  end
end