add no_deployment option

This commit is contained in:
John Bintz 2011-10-13 09:45:37 -04:00
parent f4486a9fd2
commit 5fe4778e6b
3 changed files with 26 additions and 6 deletions

View File

@ -5,7 +5,7 @@ module Penchant
attr_reader :path attr_reader :path
class << self class << self
def do_full_env_switch!(env) def do_full_env_switch!(env, deployment = false)
gemfile = Penchant::Gemfile.new gemfile = Penchant::Gemfile.new
gemfile.run_dot_penchant!(env) gemfile.run_dot_penchant!(env)
@ -45,12 +45,12 @@ module Penchant
File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1] File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1]
end end
def switch_to!(gemfile_env = nil) def switch_to!(gemfile_env = nil, deployment = false)
@env = gemfile_env @env, @is_deployment = gemfile_env, deployment
template = File.read(gemfile_erb_path) template = File.read(gemfile_erb_path)
File.open(gemfile_path, 'wb') do |fh| 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) fh.print ERB.new(template).result(binding)
end end
@ -68,6 +68,10 @@ module Penchant
def env(check, &block) def env(check, &block)
instance_eval(&block) if check.to_s == @env.to_s instance_eval(&block) if check.to_s == @env.to_s
end end
def no_deployment(&block)
instance_eval(&block) if !@is_deployment
end
end end
end end

View File

@ -3,9 +3,9 @@
require 'rubygems' require 'rubygems'
require 'penchant' require 'penchant'
if Penchant::Gemfile.do_full_env_switch!(ARGV[0]) if Penchant::Gemfile.do_full_env_switch!(ARGV[0], true)
system %{bundle} system %{bundle}
puts "Gemfile switched to #{ARGV[0]}" puts "Gemfile switched to #{ARGV[0]} in deployment mode"
else else
exit 0 exit 0
end end

View File

@ -77,6 +77,10 @@ GEMFILE
not not
<% end %> <% end %>
<% no_deployment do %>
diddeploy
<% end %>
all all
ERB ERB
@ -84,6 +88,7 @@ ERB
subject.switch_to!(:test) subject.switch_to!(:test)
File.read('Gemfile').should include('test') File.read('Gemfile').should include('test')
File.read('Gemfile').should include('diddeploy')
File.read('Gemfile').should_not include('not') File.read('Gemfile').should_not include('not')
File.read('Gemfile').should include('all') File.read('Gemfile').should include('all')
end end
@ -92,6 +97,7 @@ ERB
subject.switch_to!(:not) subject.switch_to!(:not)
File.read('Gemfile').should_not include('test') File.read('Gemfile').should_not include('test')
File.read('Gemfile').should include('diddeploy')
File.read('Gemfile').should include('not') File.read('Gemfile').should include('not')
File.read('Gemfile').should include('all') File.read('Gemfile').should include('all')
end end
@ -101,6 +107,16 @@ ERB
File.read('Gemfile').should_not include('test') File.read('Gemfile').should_not include('test')
File.read('Gemfile').should_not include('not') 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') File.read('Gemfile').should include('all')
end end