class Fyodor::ConfigGetter

Constants

DEFAULT_CONFIG_PATH
DEFAULT_TEMPLATE_PATH

Public Instance Methods

config() click to toggle source
# File lib/fyodor/config_getter.rb, line 11
def config
  return @config if defined?(@config)

  Hash.include CoreExtensions::Hash::Merging
  config = default_config.deep_merge(user_config)
  config["output"]["template"] = template

  @config = config
end

Private Instance Methods

config_dir() click to toggle source
# File lib/fyodor/config_getter.rb, line 24
def config_dir
  @config_dir ||= Pathname.new(ENV["XDG_CONFIG_HOME"] || "~/.config").expand_path + "fyodor"
end
default_config() click to toggle source
# File lib/fyodor/config_getter.rb, line 46
def default_config
  @default_config ||= TOML.load_file(DEFAULT_CONFIG_PATH)
end
template() click to toggle source
# File lib/fyodor/config_getter.rb, line 50
def template
  if user_template_path.exist?
    puts "Using custom template at #{user_template_path}.\n\n"
    return File.read(user_template_path)
  end

  puts "No custom template found: using default.\n\n"
  File.read(DEFAULT_TEMPLATE_PATH)
end
user_config() click to toggle source
# File lib/fyodor/config_getter.rb, line 36
def user_config
  if user_config_path.exist?
    puts "Using config at #{user_config_path}.\n"
    return TOML.load_file(user_config_path)
  end

  puts "No config found: using defaults.\n"
  {}
end
user_config_path() click to toggle source
# File lib/fyodor/config_getter.rb, line 28
def user_config_path
  config_dir + "fyodor.toml"
end
user_template_path() click to toggle source
# File lib/fyodor/config_getter.rb, line 32
def user_template_path
  config_dir + "template.erb"
end