Sha256: 724fe4b9333b0f3bf95882cd40c50225cbd6aa421085264c7e927035dd4bac24
Contents?: true
Size: 924 Bytes
Versions: 3
Compression:
Stored size: 924 Bytes
Contents
# frozen_string_literal: true require 'pathname' require 'yaml' module AtCoderFriends # loads configuration file from the specified directory. class ConfigLoader DOTFILE = '.at_coder_friends.yml' class << self def load_config(target_dir) path = find_file_upwards(DOTFILE, target_dir) load_yaml(path) end def find_file_upwards(filename, start_dir) Pathname.new(start_dir).expand_path.ascend do |dir| file = dir + filename return file.to_s if file.exist? end raise ConfigNotFoundError, "Configuration file not found: #{start_dir}" end def load_yaml(path) yaml = IO.read(path, encoding: Encoding::UTF_8) YAML.safe_load(yaml, [], [], false, path) rescue Errno::ENOENT raise ConfigNotFoundError, "Configuration file not found: #{path}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
at_coder_friends-0.3.3 | lib/at_coder_friends/config_loader.rb |
at_coder_friends-0.3.2 | lib/at_coder_friends/config_loader.rb |
at_coder_friends-0.3.1 | lib/at_coder_friends/config_loader.rb |