class GitContext::Storage::Git
Attributes
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/git_context/storage/git.rb, line 10 def initialize(config) @config = config end
Public Instance Methods
reset()
click to toggle source
# File lib/git_context/storage/git.rb, line 21 def reset FileUtils.rm(contexts_filepath) FileUtils.rm_r(profiles_dir) create_contexts_file create_profiles_dir end
save()
click to toggle source
# File lib/git_context/storage/git.rb, line 29 def save reset save_profiles save_contexts end
setup()
click to toggle source
# File lib/git_context/storage/git.rb, line 14 def setup create_contexts_file create_profiles_dir include(global_gitconfig_path, contexts_filepath) end
Private Instance Methods
add_context(contexts_file, dir, profile_file)
click to toggle source
# File lib/git_context/storage/git.rb, line 66 def add_context(contexts_file, dir, profile_file) `git config -f "#{contexts_file}" --add "includeIf.gitdir:#{dir}/.path" "#{profile_file}"` end
add_profile(profile_file, profile)
click to toggle source
# File lib/git_context/storage/git.rb, line 60 def add_profile(profile_file, profile) `git config -f "#{profile_file}" --add user.name "#{profile.user.name}"` `git config -f "#{profile_file}" --add user.email "#{profile.user.email}"` `git config -f "#{profile_file}" --add user.signingKey "#{profile.user.signing_key}"` end
contexts_filepath()
click to toggle source
# File lib/git_context/storage/git.rb, line 91 def contexts_filepath File.join(git_context_dir, CONTEXTS_FILE) end
create_contexts_file()
click to toggle source
# File lib/git_context/storage/git.rb, line 79 def create_contexts_file touch_file(contexts_filepath) end
create_dir(dir)
click to toggle source
# File lib/git_context/storage/git.rb, line 111 def create_dir(dir) FileUtils.mkdir(dir) unless FileTest.exists?(dir) end
create_profiles_dir()
click to toggle source
# File lib/git_context/storage/git.rb, line 83 def create_profiles_dir create_dir(profiles_dir) end
git_context_dir()
click to toggle source
# File lib/git_context/storage/git.rb, line 95 def git_context_dir File.join(home, BASE_STORAGE_DIR) end
global_gitconfig_path()
click to toggle source
# File lib/git_context/storage/git.rb, line 87 def global_gitconfig_path File.join(home, GITCONFIG_FILE) end
home()
click to toggle source
# File lib/git_context/storage/git.rb, line 75 def home config.home end
include(gitconfig_path, contexts_filepath)
click to toggle source
# File lib/git_context/storage/git.rb, line 54 def include(gitconfig_path, contexts_filepath) return if included?(gitconfig_path, contexts_filepath) `git config -f "#{gitconfig_path}" --add "include.path" "#{contexts_filepath}"` end
included?(gitconfig_path, contexts_filepath)
click to toggle source
# File lib/git_context/storage/git.rb, line 70 def included?(gitconfig_path, contexts_filepath) include_path = `git config -f "#{gitconfig_path}" include.path` include_path.include?(contexts_filepath) end
profile_filepath(profile_name)
click to toggle source
# File lib/git_context/storage/git.rb, line 103 def profile_filepath(profile_name) File.join(profiles_dir, profile_name) end
profiles_dir()
click to toggle source
# File lib/git_context/storage/git.rb, line 99 def profiles_dir File.join(git_context_dir, PROFILES_DIR) end
save_contexts()
click to toggle source
# File lib/git_context/storage/git.rb, line 37 def save_contexts config.contexts.each do |context| profile_file = profile_filepath(context.profile_name) add_context(contexts_filepath, context.work_dir, profile_file) end end
save_profiles()
click to toggle source
# File lib/git_context/storage/git.rb, line 45 def save_profiles config.profiles.each do |profile| profile_file = profile_filepath(profile.profile_name) touch_file(profile_file) add_profile(profile_file, profile) end end
touch_file(config_file_path)
click to toggle source
# File lib/git_context/storage/git.rb, line 107 def touch_file(config_file_path) FileUtils.touch(config_file_path) end