lib/lite_config.rb in lite_config-0.0.1 vs lib/lite_config.rb in lite_config-0.0.2
- old
+ new
@@ -14,27 +14,35 @@
name = name.to_sym
@configs ||= {}
@configs.key?(name) ? @configs[name] : (@configs[name] = HashWithIndifferentAccess.new(load(name)))
end
- def set_config_path(path)
+ def config_path=(path)
raise ImmutableError, "config_path is frozen after the first file load" unless @configs.nil?
@config_path = path
end
+ def app_env=(app_env)
+ raise ImmutableError, "app_env is frozen after the first file load" unless @configs.nil?
+
+ @app_env = app_env
+ end
+
def reset
@configs = nil
end
private
def load(name)
config = load_single(config_filename(name))
if File.exist?(local_config_filename(name))
- config.deep_merge!(load_single(local_config_filename(name)))
+ local_config = load_single(local_config_filename(name))
+
+ config.deep_merge!(local_config) if local_config
end
raise "Oops, no #{app_env} config found for #{name} in #{filename}" unless config
config
@@ -56,13 +64,10 @@
def local_config_filename(name)
config_filename(name).gsub(/.yml$/, '_local.yml')
end
- def active_config_filename(name)
- end
-
def app_root
defined?(Rails) ? Rails.root : `pwd`.strip
end
def app_env
@@ -77,10 +82,10 @@
'development'
end
end
def has_environmenty_key?(hash)
- %w(development test production).any?{ |envy| hash.key?(envy) }
+ %w(development test production).any?{ |envy| hash.key?(envy) } if hash
end
end
def LiteConfig(name)
LiteConfig.fetch(name)