require 'yaml' module Envvy class Railtie < Rails::Railtie attr_accessor :env 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 if Rails.env.development? require 'filewatch/watch' conf_watcher = FileWatch::Watch.new conf_watcher.watch(env_vars) 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)) end def get(key, &block) if block_given? yield self.env[key] else return self.env[key] end end end end