Class: Pdfh::SettingsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfh/utils/settings_builder.rb

Overview

Loads or creates a default settings yaml file

Constant Summary collapse

CONFIG_FILE_LOCATIONS =
[Dir.pwd, ENV.fetch("XDG_CONFIG_HOME", "~/.config"), "~"].freeze
SUPPORTED_EXTENSIONS =
%w[yml yaml].freeze
ENV_VAR =
"PDFH_CONFIG_FILE"

Class Method Summary collapse

Class Method Details

.buildPdfh::Settings

Returns:



12
13
14
15
16
17
18
19
20
21
# File 'lib/pdfh/utils/settings_builder.rb', line 12

def build
  env_config_file = ENV.fetch(ENV_VAR, nil)
  raise "File path in #{ENV_VAR} not found" if env_config_file && !File.exist?(env_config_file)

  config_file = env_config_file || search_config_file
  file_hash = YAML.load_file(config_file, symbolize_names: true)
  Pdfh.debug "Loaded configuration file: #{config_file}"

  Settings.new(file_hash)
end