class Rebuild::GitConfig
Public Class Methods
new()
click to toggle source
# File lib/rebuild/git_config.rb, line 9 def initialize return unless File.exists?(gitconfig_path) @config = ParseConfig.new(gitconfig_path) end
Public Instance Methods
add_rebuild_config()
click to toggle source
# File lib/rebuild/git_config.rb, line 19 def add_rebuild_config git_config = if File.exists?(gitconfig_path) File.read(gitconfig_path) else '' end rebuild_config = <<-EOS.unindent [rebuild] # if true, everytime git pull update = false # you can change script run directory scriptdir = / # if present, you can `rebuild` without argument # repo = username/dotfiles # cloned directory path # directory = ~/src/dotfiles EOS File.write(gitconfig_path, "#{git_config}\n#{rebuild_config}") Logger.info('Succeed to update ~/.gitconfig') end
has_rebuild_config?()
click to toggle source
# File lib/rebuild/git_config.rb, line 14 def has_rebuild_config? return false unless @config @config.params["rebuild"] != nil end
rebuild_config()
click to toggle source
# File lib/rebuild/git_config.rb, line 45 def rebuild_config return {} unless @config symbolize_keys(@config.params["rebuild"] || {}) end
Private Instance Methods
gitconfig_path()
click to toggle source
# File lib/rebuild/git_config.rb, line 73 def gitconfig_path File.expand_path('~/.gitconfig') end
normalize_value(value)
click to toggle source
TODO: Migrate from parseconfig
# File lib/rebuild/git_config.rb, line 62 def normalize_value(value) case value when 'true' true when 'false' false else value end end
symbolize_keys(hash)
click to toggle source
# File lib/rebuild/git_config.rb, line 52 def symbolize_keys(hash) symbolized = {} hash.each do |key, value| symbolized[key.to_sym] = normalize_value(value) end symbolized end