Sha256: 336a6e1077b68474314987b448eae53c9b71c9ae2ad68daca2e145c4232e1f89
Contents?: true
Size: 1.18 KB
Versions: 6
Compression:
Stored size: 1.18 KB
Contents
require 'clicoder' module Clicoder class Config attr_accessor :global, :local def initialize global_config_file = "#{global_config_dir}/config.yml" @global = File.exists?(global_config_file) ? YAML::load_file(global_config_file) : {} local_config_file = '.config.yml' @local = File.exists?(local_config_file) ? YAML::load_file(local_config_file) : {} end # NOTE: This is not a class variable in order to evaluate stubbed ENV['HOME'] on each RSpec run def global_config_dir @global_config_dir ||= "#{ENV['HOME']}/.clicoder.d" end def asset(asset_name) site_name = get('site') file_name = get(site_name, asset_name) if file_name.empty? file_name = get('default', asset_name) end unless file_name.empty? return File.expand_path(file_name, global_config_dir) else return '' end end def merged_config @merged_config ||= global.merge(local) end def get(*keys) conf = merged_config begin keys.each do |key| conf = conf[key] end return conf.nil? ? '' : conf rescue return '' end end end end
Version data entries
6 entries across 6 versions & 1 rubygems