lib/envvy/railtie.rb in envvy-1.0.2 vs lib/envvy/railtie.rb in envvy-1.0.3

- old
+ new

@@ -2,37 +2,44 @@ module Envvy class Railtie < Rails::Railtie attr_accessor :env + class << self + attr_accessor :config_path + + def config_path + @config_path || File.join(Rails.root, "config", "env_vars.yml") + end + end + config.before_initialize do self.get("config") do |config| config.each do |k, v| ENV[k.to_s.upcase] = v end end end config.before_configuration do - env_vars = File.join(Rails.root, "config", "env_vars.yml") - set_env env_vars + set_env self.config_path if Rails.env.development? require 'filewatch/watch' conf_watcher = FileWatch::Watch.new - conf_watcher.watch(env_vars) + conf_watcher.watch(self.config_path) Thread.new do conf_watcher.subscribe(1,5) do |status, path| set_env path end end end end def set_env file - self.env = YAML.load(File.read(file)) + self.env = if File.exist?(file) then YAML.load(File.read(file)) else {} end end def get(key, &block) if block_given? yield self.env[key]