Class: Pdfh::Services::SettingsBuilder
- Inherits:
-
Object
- Object
- Pdfh::Services::SettingsBuilder
- Defined in:
- lib/pdfh/services/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"- DOCUMENT_TYPE_TEMPLATE =
{ name: "Example Name", re_id: "EXAMPLE MATCH", re_date: "(\d{2})/(?<m>\w+)/(?<y>\d{4})", store_path: "{YEAR}/sub folder", name_template: "{period} {original}" }.freeze
- SETTINGS_TEMPLATE =
{ lookup_dirs: ["~/Downloads"].freeze, destination_base_path: "~/Documents", document_types: [DOCUMENT_TYPE_TEMPLATE].freeze }.freeze
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(program_name: nil) ⇒ SettingsBuilder
33 34 35 |
# File 'lib/pdfh/services/settings_builder.rb', line 33 def initialize(program_name: nil) @program_name = program_name || PROGRAM_NAME end |
Class Method Details
.call(program_name: nil) ⇒ Settings
27 28 29 |
# File 'lib/pdfh/services/settings_builder.rb', line 27 def self.call(program_name: nil) new(program_name: program_name).call end |
Instance Method Details
#call ⇒ Settings
38 39 40 41 42 43 44 45 |
# File 'lib/pdfh/services/settings_builder.rb', line 38 def call config_file = find_config_file file_hash = YAML.load_file(config_file, symbolize_names: true) Pdfh.logger.debug "Loaded configuration file: #{config_file}" validated = Services::SettingsValidator.call(file_hash) Settings.new(**validated) end |