module MergeDBSchema::Init
Public Class Methods
init(argv)
click to toggle source
# File lib/merge_db_schema/init.rb, line 6 def init(argv) force = argv[0] == '--force' check_git_dir! init_gitattribute init_gitconfig(force) end
Private Class Methods
check_git_dir!()
click to toggle source
# File lib/merge_db_schema/init.rb, line 15 def check_git_dir! raise NotGitDirectoryError, 'Current directory is not managed by git!' unless Pathname('.git').exist? end
init_gitattribute()
click to toggle source
# File lib/merge_db_schema/init.rb, line 19 def init_gitattribute print 'Initializing .gitattributes ... ' gitattributes_content = "db/schema.rb merge=merge_db_schema\n" gitattr = Pathname('.gitattributes') if gitattr.exist? && gitattr.read.include?(gitattributes_content) puts Rainbow('skip').orange else gitattr.open('a') do |f| f.write(gitattributes_content) end puts Rainbow('done!').green end end
init_gitconfig(force)
click to toggle source
# File lib/merge_db_schema/init.rb, line 33 def init_gitconfig(force) gitconfig_content = <<~END [merge "merge_db_schema"] \tname = Merge db/schema.rb \tdriver = merge_db_schema %O %A %B \trecursive = text END unless force puts 'Add the following code into .git/config, initializing is completed!' puts puts gitconfig_content return end gitconfig = Pathname('.git/config') print 'Initializing .git/config ... ' if gitconfig.exist? && gitconfig.read.include?(gitconfig_content) puts Rainbow('skip').orange else gitconfig.open('a') do |f| f.write(gitconfig_content) end puts Rainbow('done!').green end puts Rainbow('Successfully initialized!') end