add no_deployment option
This commit is contained in:
parent
f4486a9fd2
commit
5fe4778e6b
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user