class AppConfig
Public Class Methods
config_path_for(env)
click to toggle source
# File lib/app_config.rb, line 15 def config_path_for(env) "config/#{env}/config.json" end
default_filename()
click to toggle source
# File lib/app_config.rb, line 11 def default_filename config_path_for(Environment.environment) end
load()
click to toggle source
# File lib/app_config.rb, line 7 def load new(app_config_path).load end
new(filename = "")
click to toggle source
# File lib/app_config.rb, line 30 def initialize(filename = "") @filename = filename.empty? ? AppConfig.default_filename : filename end
Private Class Methods
app_config_path()
click to toggle source
# File lib/app_config.rb, line 21 def app_config_path expand_path(Options.get("config.path")) end
expand_path(path)
click to toggle source
# File lib/app_config.rb, line 25 def expand_path(path) `echo #{path}`.chomp end
Public Instance Methods
load()
click to toggle source
# File lib/app_config.rb, line 34 def load config['environment']&.each do |key, value| ENV[key] = value.is_a?(Hash) || value.is_a?(Array) ? value.to_json : value.to_s end end
Private Instance Methods
config()
click to toggle source
# File lib/app_config.rb, line 42 def config @config ||= file_contents ? YAML.safe_load(file_contents) : {} rescue YAML::SyntaxError => e raise ParsingError, "#{@filename}: #{e}" end
file_contents()
click to toggle source
# File lib/app_config.rb, line 48 def file_contents @file_contents ||= begin File.open(@filename).read rescue Errno::ENOENT nil end end