lib/powify/app.rb in powify-0.8.5 vs lib/powify/app.rb in powify-0.9.1

- old
+ new

@@ -1,9 +1,9 @@ module Powify class App extend Powify - AVAILABLE_METHODS = %w(create link new destroy unlink remove restart always_restart always_restart_off browse open rename environment env logs help) + AVAILABLE_METHODS = %w(create link new destroy unlink remove restart always_restart always_restart_off browse open rename environment env logs) class << self def run(args) method = args[0].strip.to_s.downcase raise "The command `#{args.first}` does not exist!" unless AVAILABLE_METHODS.include?(method) @@ -70,11 +70,11 @@ else $stdout.puts "Powify could not find an app to always restart with the name #{app_name}" $stdout.puts "Type `powify server list` for a full list of applications." end end - + # powify always_restart_off # powify always_restart_off foo def always_restart_off(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) restart_txt_path = "#{POWPATH}/#{app_name}/tmp/always_restart.txt" @@ -121,12 +121,20 @@ # powify environment foo production def environment(args = []) return if args.empty? app_name, env = File.basename(current_path), args[0].strip.to_s.downcase app_name, env = args[0].strip.to_s.downcase, args[1].strip.to_s.downcase if args.size > 1 - symlink_path = "#{POWPATH}/#{app_name}" - %x{echo export RAILS_ENV=#{env} > #{symlink_path}/.powenv} + env_file = "#{POWPATH}/#{app_name}/.powenv" + if File.exists?(env_file) + contents = File.readlines(env_file).reject do |line| + # Ignore empty lines and lines that define the environment. + line.strip.empty? || line.match(/^export RAILS_ENV=(.+)/) + end.compact << "export RAILS_ENV=#{env}" + File.open(env_file, "w") { |f| f.puts contents } + else + %x{echo export RAILS_ENV=#{env} > #{env_file}} + end $stdout.puts "Successfully changed environment to #{env}." restart [app_name] end alias_method :env, :environment @@ -137,6 +145,6 @@ symlink_path = "#{POWPATH}/#{app_name}" system "tail -f #{symlink_path}/log/#{ENV['RAILS_ENV']||'development'}.log" end end end -end \ No newline at end of file +end