lib/lite_config.rb in lite_config-0.0.3 vs lib/lite_config.rb in lite_config-0.0.4
- old
+ new
@@ -1,22 +1,23 @@
require "lite_config/version"
-require 'active_support/core_ext/hash/deep_merge'
-require 'active_support/core_ext/hash/indifferent_access'
+require 'lite_config/hash'
+require 'lite_config/hash_with_indifferent_access'
require 'yaml'
+require 'erb'
module LiteConfig
class ImmutableError < StandardError; end
class NotFoundError < StandardError; end
extend self
def fetch(name)
name = name.to_sym
@configs ||= {}
- @configs.key?(name) ? @configs[name] : (@configs[name] = HashWithIndifferentAccess.new(load(name)))
+ @configs.key?(name) ? @configs[name] : (@configs[name] = IndifferentHash.new(load(name)))
end
def config_path=(path)
raise ImmutableError, "config_path is frozen after the first file load" unless @configs.nil?
@@ -50,20 +51,26 @@
config
end
def load_single(filename)
- hash = YAML.load_file(filename)
+ hash = if File.extname(filename) == '.erb'
+ YAML.load ERB.new(IO.read(filename)).result
+ else
+ YAML.load_file filename
+ end
has_environmenty_key?(hash) ? hash[app_env] : hash
end
def config_path
@config_path ||= File.join(app_root, 'config')
end
def config_filename(name)
- File.join(config_path, name.to_s + '.yml')
+ filename = File.join(config_path, name.to_s + '.yml')
+ filename << '.erb' if File.exist?(filename + '.erb')
+ filename
end
def local_config_filename(name)
config_filename(name).gsub(/.yml$/, '_local.yml')
end