clean up file/directory interaction, add some tests

This commit is contained in:
David Dollar
2012-04-23 15:50:23 -04:00
parent 55f274532f
commit 638005403f
4 changed files with 42 additions and 7 deletions
+6 -5
View File
@@ -79,14 +79,15 @@ private ######################################################################
end
def engine
root = File.expand_path(File.dirname(procfile))
env = File.expand_path(File.join(root, ".env"))
@engine ||= Foreman::Engine.new(procfile, options.merge({:app_root => root,
:env => env}))
@engine ||= Foreman::Engine.new(procfile, options)
end
def procfile
options[:procfile] || "Procfile"
case
when options[:procfile] then options[:procfile]
when options[:app_root] then File.expand_path(File.join(options[:app_root], "Procfile"))
else "Procfile"
end
end
def error(message)
+10 -2
View File
@@ -22,10 +22,12 @@ class Foreman::Engine
def initialize(procfile, options={})
@procfile = Foreman::Procfile.new(procfile)
@directory = options[:app_root]
@directory = options[:app_root] || File.expand_path(File.dirname(procfile))
@options = options.dup
@environment = read_environment_files(options[:env])
@output_mutex = Mutex.new
@options[:env] ||= default_env
@environment = read_environment_files(@options[:env])
end
def start
@@ -216,4 +218,10 @@ private ######################################################################
environment
end
def default_env
env = File.join(directory, ".env")
File.exists?(env) ? env : ""
end
end