lib/anyway/config.rb in anyway_config-0.5.1 vs lib/anyway/config.rb in anyway_config-1.0.0.rc1
- old
+ new
@@ -1,10 +1,12 @@
+# frozen_string_literal: true
+
require 'anyway/ext/class'
require 'anyway/ext/deep_dup'
require 'anyway/ext/hash'
-module Anyway
+module Anyway # :nodoc:
using Anyway::Ext::Class
using Anyway::Ext::DeepDup
using Anyway::Ext::Hash
# Base config class
@@ -71,25 +73,34 @@
load_from_file(config)
load_from_env(config)
end
def load_from_file(config)
- config_path = (Anyway.env.send(config_name) || {}).delete('conf')
+ config_path = Anyway.env.fetch(config_name).delete('conf') ||
+ "./config/#{config_name}.yml"
if config_path && File.file?(config_path)
- require 'yaml'
- config.deep_merge!(YAML.load_file(config_path) || {})
+ config.deep_merge!(parse_yml(config_path) || {})
end
config
end
def load_from_env(config)
- config.deep_merge!(Anyway.env.send(config_name) || {})
+ config.deep_merge!(Anyway.env.fetch(config_name))
config
end
private
def set_value(key, val)
send("#{key}=", val) if respond_to?(key)
+ end
+
+ def parse_yml(path)
+ require 'yaml'
+ if defined?(ERB)
+ YAML.safe_load(ERB.new(File.read(path)).result)
+ else
+ YAML.load_file(path)
+ end
end
end
end