class Dotfiler::Config

Constants

CONFIG_FILE
DOTFILES_FILE
RELATIVE_HOME_PATH

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/dotfiler/config.rb, line 11
def initialize(*args)
  super
  @data = load_data
end

Public Instance Methods

[](setting) click to toggle source
# File lib/dotfiler/config.rb, line 16
def [](setting)
  @data[setting]
end
dotfiles_file_name() click to toggle source
# File lib/dotfiler/config.rb, line 40
def dotfiles_file_name
  DOTFILES_FILE
end
dotfiles_file_path() click to toggle source
# File lib/dotfiler/config.rb, line 36
def dotfiles_file_path
  path(self[:dotfiles]).join(dotfiles_file_name) if set?
end
file_path() click to toggle source
# File lib/dotfiler/config.rb, line 20
def file_path
  @_file_path ||= home_path.join(CONFIG_FILE)
end
home_path() click to toggle source
# File lib/dotfiler/config.rb, line 24
def home_path
  @_home_path ||= path(ENV["DOTFILER_HOME"] || Dir.home)
end
relative_home_path() click to toggle source
# File lib/dotfiler/config.rb, line 28
def relative_home_path
  @_relative_home_path ||= path(RELATIVE_HOME_PATH, expand: false)
end
reload!() click to toggle source
# File lib/dotfiler/config.rb, line 44
def reload!
  @data = load_data
end
set?() click to toggle source
# File lib/dotfiler/config.rb, line 32
def set?
  file_path.exists?
end
update!(args = {}) click to toggle source
# File lib/dotfiler/config.rb, line 48
def update!(args = {})
  new_data     = @data.merge(args)
  file_content = new_data.each_with_object([]) { |(k, v), result| result << "#{k}: #{v}" }.join("\n")

  fs.create_file(file_path.to_s, file_content)

  reload!
end

Private Instance Methods

load_data() click to toggle source
# File lib/dotfiler/config.rb, line 63
def load_data
  return {} unless set?

  (YAML.load_file(file_path.to_s) || {}).each_with_object({}) do |(setting, value), result|
    result[setting.to_sym] = value
  end
end
path(input, *opts) click to toggle source
# File lib/dotfiler/config.rb, line 59
def path(input, *opts)
  to_path.(input, *opts)
end