Module: CodeBuddy::Server
- Defined in:
- lib/code_buddy/server.rb
Class Method Summary collapse
Class Method Details
.running? ⇒ Boolean
39 40 41 |
# File 'lib/code_buddy/server.rb', line 39 def running? `lsof -i :4567`.split("\n").find{|process_line| process_line =~ /ruby/} end |
.start ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/code_buddy/server.rb', line 5 def start if running? puts "Code Buddy is already running." exit else Daemons.daemonize(:app_name => "code_buddy_server") CodeBuddy::App.run! :host => 'localhost' end end |
.stop ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/code_buddy/server.rb', line 15 def stop if process_line = running? pid = process_line.split[1] Process.kill("TERM", pid.to_i) else puts "Code Buddy is not running." exit end end |
.update(stack_string) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/code_buddy/server.rb', line 25 def update(stack_string) require 'net/http' require 'uri' require 'launchy' if running? Net::HTTP.post_form(URI.parse('http://localhost:4567/new'), {"stack" => stack_string}) else CodeBuddy::App.stack_string = stack_string start end Launchy.open("http://localhost:4567/stack/0") end |