Class: Devserver::CommandManager
- Inherits:
-
Object
- Object
- Devserver::CommandManager
- Defined in:
- lib/devserver/command_manager.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#pid_file ⇒ Object
Returns the value of attribute pid_file.
-
#port ⇒ Object
Returns the value of attribute port.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#command(mode = self.mode) ⇒ String
returns command for @server and @mode (start, stop, debug).
-
#determine_app_root ⇒ String
Pretend that we are checking for rails by checking for config/boot.rb we’ll even do something smart for ourselves by chdir ..
-
#initialize(options = {}) ⇒ CommandManager
constructor
raises DevserverError if it doesn’t appear we are in or one level down of a rails directory.
-
#is_port_open? ⇒ Boolean
check to see if anything is still running on @port.
-
#start_command(mode = self.mode) ⇒ String
builds the start command for @server.
- #start_devserver(mode = self.mode) ⇒ Object
-
#start_options(mode = self.mode) ⇒ String
builds the command options with regard to the specified server.
-
#stop_command ⇒ String
builds the stop command for @server.
- #stop_devserver ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CommandManager
raises DevserverError if it doesn’t appear we are in or one level down of a rails directory
10 11 12 13 14 |
# File 'lib/devserver/command_manager.rb', line 10 def initialize( = {}) .keys.each do |key| self.instance_variable_set("@#{key.to_s}",[key]) end end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def environment @environment end |
#log_file ⇒ Object
Returns the value of attribute log_file.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def log_file @log_file end |
#mode ⇒ Object
Returns the value of attribute mode.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def mode @mode end |
#pid_file ⇒ Object
Returns the value of attribute pid_file.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def pid_file @pid_file end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def port @port end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/devserver/command_manager.rb', line 6 def server @server end |
Instance Method Details
#command(mode = self.mode) ⇒ String
returns command for @server and @mode (start, stop, debug)
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/devserver/command_manager.rb', line 89 def command(mode = self.mode) case mode when 'start' self.start_command(mode) when 'debug' self.start_command(mode) when 'stop' self.stop_command else raise DevserverError, "Unrecognized mode: #{mode}" end end |
#determine_app_root ⇒ String
Pretend that we are checking for rails by checking for config/boot.rb we’ll even do something smart for ourselves by chdir .. if ../config/boot.rb exists. “smart for ourselves” is the operative phrase
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/devserver/command_manager.rb', line 21 def determine_app_root if(File.exist?('config/boot.rb')) return Dir.pwd elsif(File.exist?('../config/boot.rb')) Dir.chdir('..') return Dir.pwd else return nil end end |
#is_port_open? ⇒ Boolean
check to see if anything is still running on @port
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/devserver/command_manager.rb', line 105 def is_port_open? begin Timeout::timeout(1) do begin s = TCPSocket.new('127.0.0.1', self.port) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end end rescue Timeout::Error end return false end |
#start_command(mode = self.mode) ⇒ String
builds the start command for @server
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/devserver/command_manager.rb', line 57 def start_command(mode = self.mode) case self.server when 'passenger' "passenger start #{self.start_options(mode)}" when 'thin' "thin #{self.start_options(mode)} start" when 'mongrel' "mongrel_rails start #{self.start_options(mode)}" else raise DevserverError, "Unrecognized web server: #{self.server}" end end |
#start_devserver(mode = self.mode) ⇒ Object
121 122 123 |
# File 'lib/devserver/command_manager.rb', line 121 def start_devserver(mode = self.mode) system("#{self.start_command(mode)}") end |
#start_options(mode = self.mode) ⇒ String
builds the command options with regard to the specified server
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/devserver/command_manager.rb', line 36 def (mode = self.mode) = "--port #{self.port} --environment #{self.environment}" if(mode == 'debug') += " --debug" end case self.server when 'passenger' "#{common_options} --log-file #{self.log_file} --pid-file #{self.pid_file}" when 'thin' "#{common_options} --log #{self.log_file} --pid #{self.pid_file}" when 'mongrel' "#{common_options} --log #{self.log_file} --pid #{self.pid_file}" else nil end end |
#stop_command ⇒ String
builds the stop command for @server
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/devserver/command_manager.rb', line 73 def stop_command case self.server when 'passenger' "passenger stop --pid-file #{self.pid_file}" when 'thin' "thin --pid #{self.pid_file} stop" when 'mongrel' "mongrel_rails stop --pid #{self.pid_file}" else raise DevserverError, "Unrecognized web server: #{self.server}" end end |
#stop_devserver ⇒ Object
125 126 127 |
# File 'lib/devserver/command_manager.rb', line 125 def stop_devserver system("#{self.stop_command}") end |