From 5fe4778e6b84c51322e8f1eda5ebed179c70ee56 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 13 Oct 2011 09:45:37 -0400 Subject: [PATCH] add no_deployment option --- lib/penchant/gemfile.rb | 12 ++++++++---- script/gemfile | 4 ++-- spec/lib/penchant/gemfile_spec.rb | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 502151a..61b5fe6 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -5,7 +5,7 @@ module Penchant attr_reader :path class << self - def do_full_env_switch!(env) + def do_full_env_switch!(env, deployment = false) gemfile = Penchant::Gemfile.new gemfile.run_dot_penchant!(env) @@ -45,12 +45,12 @@ module Penchant File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1] end - def switch_to!(gemfile_env = nil) - @env = gemfile_env + def switch_to!(gemfile_env = nil, deployment = false) + @env, @is_deployment = gemfile_env, deployment template = File.read(gemfile_erb_path) File.open(gemfile_path, 'wb') do |fh| - fh.puts "# generated by penchant, environment: #{@env}" + fh.puts "# generated by penchant, environment: #{@env || "none"}#{@is_deployment ? " , deployment mode" : ""}" fh.print ERB.new(template).result(binding) end @@ -68,6 +68,10 @@ module Penchant def env(check, &block) instance_eval(&block) if check.to_s == @env.to_s end + + def no_deployment(&block) + instance_eval(&block) if !@is_deployment + end end end diff --git a/script/gemfile b/script/gemfile index a4aec05..1edd3b3 100755 --- a/script/gemfile +++ b/script/gemfile @@ -3,9 +3,9 @@ require 'rubygems' require 'penchant' -if Penchant::Gemfile.do_full_env_switch!(ARGV[0]) +if Penchant::Gemfile.do_full_env_switch!(ARGV[0], true) system %{bundle} - puts "Gemfile switched to #{ARGV[0]}" + puts "Gemfile switched to #{ARGV[0]} in deployment mode" else exit 0 end diff --git a/spec/lib/penchant/gemfile_spec.rb b/spec/lib/penchant/gemfile_spec.rb index 6b4d27b..bdacc92 100644 --- a/spec/lib/penchant/gemfile_spec.rb +++ b/spec/lib/penchant/gemfile_spec.rb @@ -77,6 +77,10 @@ GEMFILE not <% end %> +<% no_deployment do %> + diddeploy +<% end %> + all ERB @@ -84,6 +88,7 @@ ERB subject.switch_to!(:test) File.read('Gemfile').should include('test') + File.read('Gemfile').should include('diddeploy') File.read('Gemfile').should_not include('not') File.read('Gemfile').should include('all') end @@ -92,6 +97,7 @@ ERB subject.switch_to!(:not) File.read('Gemfile').should_not include('test') + File.read('Gemfile').should include('diddeploy') File.read('Gemfile').should include('not') File.read('Gemfile').should include('all') end @@ -101,6 +107,16 @@ ERB File.read('Gemfile').should_not include('test') File.read('Gemfile').should_not include('not') + File.read('Gemfile').should include('diddeploy') + File.read('Gemfile').should include('all') + end + + it 'should skip no_deployment sections' do + subject.switch_to!(nil, true) + + File.read('Gemfile').should_not include('test') + File.read('Gemfile').should_not include('not') + File.read('Gemfile').should_not include('diddeploy') File.read('Gemfile').should include('all') end