Class: Powify::App
Constant Summary collapse
- AVAILABLE_METHODS =
%w(create link new destroy unlink remove restart always_restart always_restart_off browse open rename environment env logs)
Constants included from Powify
Class Method Summary collapse
-
.always_restart(args = []) ⇒ Object
powify always_restart powify always_restart foo.
-
.always_restart_off(args = []) ⇒ Object
powify always_restart_off powify always_restart_off foo.
-
.browse(args = []) ⇒ Object
(also: open)
powify browse powify browse foo powify browse foo test.
-
.create(args = []) ⇒ Object
(also: link, new)
powify create powify create foo.
-
.destroy(args = []) ⇒ Object
(also: unlink, remove)
powify destroy powify destroy foo.
-
.environment(args = []) ⇒ Object
(also: env)
powify environment production powify environment foo production.
-
.logs(args = []) ⇒ Object
powify logs powify logs foo.
-
.rename(args = []) ⇒ Object
powify rename bar powify rename foo bar.
-
.restart(args = []) ⇒ Object
powify restart powify restart foo.
- .run(args) ⇒ Object
Methods included from Powify
config, current_path, extension
Class Method Details
.always_restart(args = []) ⇒ Object
powify always_restart powify always_restart foo
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/powify/app.rb', line 68 def always_restart(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) symlink_path = "#{POWPATH}/#{app_name}" if File.exists?(symlink_path) FileUtils.mkdir_p("#{symlink_path}/tmp") %x{touch #{symlink_path}/tmp/always_restart.txt} $stdout.puts "#{app_name} will now restart after every request!" 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 |
.always_restart_off(args = []) ⇒ Object
powify always_restart_off powify always_restart_off foo
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/powify/app.rb', line 83 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" if File.exists?(restart_txt_path) FileUtils.rm_f(restart_txt_path) $stdout.puts "#{app_name} will no longer restart after every request!" else $stdout.puts "Powify detemined that the app with name #{app_name} is not set to always restart." end end |
.browse(args = []) ⇒ Object Also known as: open
powify browse powify browse foo powify browse foo test
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/powify/app.rb', line 97 def browse(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) ext = args[1] || extension symlink_path = "#{POWPATH}/#{app_name}" if File.exists?(symlink_path) %x{open http://#{app_name}.#{ext}} else $stdout.puts "Powify could not find an app to browse with the name #{app_name}" Powify::Server.list end end |
.create(args = []) ⇒ Object Also known as: link, new
powify create powify create foo
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/powify/app.rb', line 15 def create(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) symlink_path = "#{POWPATH}/#{app_name}" unless File.exist?(symlink_path) FileUtils.ln_s(current_path, symlink_path) $stdout.puts "Successfully created pow app #{app_name}!" else $stdout.puts "App `#{app_name}` already exists." $stdout.puts "Powify skipped to create symlink." end $stdout.puts "Type `powify browse #{app_name}` to open the application in your browser." end |
.destroy(args = []) ⇒ Object Also known as: unlink, remove
powify destroy powify destroy foo
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/powify/app.rb', line 32 def destroy(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) symlink_path = "#{POWPATH}/#{app_name}" if File.exists?(symlink_path) FileUtils.rm(symlink_path) $stdout.puts "Successfully destroyed pow app #{app_name}!" $stdout.puts "If this was an accident, type `powify create #{app_name}` to re-create the app." else $stdout.puts "Powify could not find an app named `#{app_name}` on this server." $stdout.puts "By default, powify tries to look for an application with the same name as the current directory." $stdout.puts "If your application has a different name than the working directory, you'll need to specify in the command:" $stdout.puts "\n\tpowify destroy [NAME]\n\n" $stdout.puts "If your app was named `foo`, you would type:" $stdout.puts "\n\tpowify destroy foo\n\n" end end |
.environment(args = []) ⇒ Object Also known as: env
powify environment production powify environment foo production
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/powify/app.rb', line 127 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 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 |
.logs(args = []) ⇒ Object
powify logs powify logs foo
148 149 150 151 152 |
# File 'lib/powify/app.rb', line 148 def logs(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) symlink_path = "#{POWPATH}/#{app_name}" system "tail -f #{symlink_path}/log/#{ENV['RAILS_ENV']||'development'}.log" end |
.rename(args = []) ⇒ Object
powify rename bar powify rename foo bar
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/powify/app.rb', line 112 def rename(args = []) return if args.empty? original_app_name, new_app_name = File.basename(current_path), args[0].strip.to_s.downcase original_app_name, new_app_name = args[0].strip.to_s.downcase, args[1].strip.to_s.downcase if args.size > 1 original_symlink_path, new_symlink_path = "#{POWPATH}/#{original_app_name}", "#{POWPATH}/#{new_app_name}" FileUtils.rm(original_symlink_path) FileUtils.ln_s(current_path, new_symlink_path) $stdout.puts "Succesfully renamed #{original_app_name} to #{new_app_name}." $stdout.puts "Type `powify browse #{new_app_name}` to open the application in your browser." end |
.restart(args = []) ⇒ Object
powify restart powify restart foo
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/powify/app.rb', line 53 def restart(args = []) app_name = args[0] ? args[0].strip.to_s.downcase : File.basename(current_path) symlink_path = "#{POWPATH}/#{app_name}" if File.exists?(symlink_path) FileUtils.mkdir_p("#{symlink_path}/tmp") %x{touch #{symlink_path}/tmp/restart.txt} $stdout.puts "Successfully restarted #{app_name}!" else $stdout.puts "Powify could not find an app to restart with the name #{app_name}" $stdout.puts "Type `powify server list` for a full list of applications." end end |
.run(args) ⇒ Object
7 8 9 10 11 |
# File 'lib/powify/app.rb', line 7 def run(args) method = args[0].strip.to_s.downcase raise "The command `#{args.first}` does not exist!" unless AVAILABLE_METHODS.include?(method) self.send(method, args[1..-1]) end |