Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first attempt to add environmental configuration proc file

  • Loading branch information...
commit 669e80751f01962a0836160c3f9c2c5dbc785d5b 1 parent dbe5183
Ilya Katz authored
View
2  .gitignore
@@ -7,3 +7,5 @@
/pkg
/tags
/vendor
+Procfile
+.idea
View
2  lib/foreman.rb
@@ -1,5 +1,5 @@
require "foreman/version"
-
+require 'yaml'
module Foreman
class AppDoesNotExist < Exception; end
View
2  lib/foreman/engine.rb
@@ -21,7 +21,7 @@ class Foreman::Engine
Foreman::Color.enable($stdout)
def initialize(procfile, options={})
- @procfile = Foreman::Procfile.new(procfile)
+ @procfile = Foreman::Procfile.new(procfile, :slice=>options[:slice])
@directory = options[:app_root] || File.expand_path(File.dirname(procfile))
@options = options.dup
@environment = read_environment_files(options[:env])
View
29 lib/foreman/procfile.rb
@@ -1,6 +1,8 @@
require "foreman"
require "foreman/procfile_entry"
+YAML::ENGINE.yamler = 'psych'
+
# A valid Procfile entry is captured by this regex.
# All other lines are ignored.
#
@@ -13,8 +15,8 @@ class Foreman::Procfile
attr_reader :entries
- def initialize(filename)
- @entries = parse_procfile(filename)
+ def initialize(filename, options={})
+ @entries = parse_procfile(filename, options)
end
def [](name)
@@ -25,14 +27,21 @@ def process_names
entries.map(&:name)
end
-private
-
- def parse_procfile(filename)
- File.read(filename).split("\n").map do |line|
- if line =~ /^([A-Za-z0-9_]+):\s*(.+)$/
- Foreman::ProcfileEntry.new($1, $2)
- end
- end.compact
+ private
+
+ def parse_procfile(filename, options={})
+ opts = if options[:slice].nil?
+ ::YAML.load(ERB.new(File.read(filename)).result)
+ else
+ ::YAML.load(ERB.new(File.read(filename)).result)[options[:slice]]
+ end
+ if opts
+ opts.map { |name, command|
+ Foreman::ProcfileEntry.new(name, command)
+ }.compact
+ else
+ []
+ end
end
end
View
56 spec/foreman/procfile_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+require 'foreman/process'
+require 'foreman/procfile'
+
+describe "read procfile" do
+
+ it "should read procfile" do
+ write_procfile
+
+ procfile = Foreman::Procfile.new("Procfile")
+
+ procs = procfile.send(:parse_procfile, "Procfile")
+
+ procs.size.should == 2
+ procs.first.name.should == "alpha"
+ procs.first.command.should == "./alpha"
+
+ procs.last.name.should == "bravo"
+ procs.last.command.should == "./bravo"
+
+ end
+
+ describe "should write advanced procfile" do
+
+ it "should read development correctly" do
+ write_advanced_procfile
+
+ procfile = Foreman::Procfile.new("Procfile")
+
+ procs = procfile.send(:parse_procfile, "Procfile", :slice=>"development")
+
+ procs.size.should == 2
+ procs.first.name.should == "alpha_dev"
+ procs.first.command.should == "./alpha"
+
+ procs.last.name.should == "bravo_dev"
+ procs.last.command.should == "./bravo dev"
+ end
+
+ it "should read test correctly" do
+ write_advanced_procfile
+
+ procfile = Foreman::Procfile.new("Procfile")
+
+ procs = procfile.send(:parse_procfile, "Procfile", :slice=>"test")
+
+ procs.size.should == 2
+ procs.first.name.should == "alpha_test"
+ procs.first.command.should == "./alpha"
+
+ procs.last.name.should == "bravo_test"
+ procs.last.command.should == "bundle exec rake resque:work QUEUE=* &"
+ end
+
+ end
+end
View
14 spec/spec_helper.rb
@@ -47,6 +47,20 @@ def write_procfile(procfile="Procfile", alpha_env="")
File.expand_path(procfile)
end
+def write_advanced_procfile(procfile="Procfile", alpha_env="")
+ File.open(procfile, "w") do |file|
+ file.puts "development: "
+ file.puts " alpha_dev: ./alpha" + " #{alpha_env}".rstrip
+ file.puts "\n"
+ file.puts " bravo_dev:\t./bravo dev"
+ file.puts "test: "
+ file.puts " alpha_test: ./alpha" + " #{alpha_env}".rstrip
+ file.puts "\n"
+ file.puts " bravo_test:\tbundle exec rake resque:work QUEUE=* &"
+ end
+ File.expand_path(procfile)
+end
+
def write_env(env=".env", options={"FOO"=>"bar"})
File.open(env, "w") do |file|
options.each do |key, val|
Please sign in to comment.
Something went wrong with that request. Please try again.