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).
-
#command_available? ⇒ Boolean
returns true/false if the gem corresponding to self.server is installed.
-
#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
sets instance variables based on options, not limited to attr_accesor values.
-
#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
sets instance variables based on options, not limited to attr_accesor values
25 26 27 28 29 |
# File 'lib/devserver/command_manager.rb', line 25 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.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def environment @environment end |
#log_file ⇒ Object
Returns the value of attribute log_file.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def log_file @log_file end |
#mode ⇒ Object
Returns the value of attribute mode.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def mode @mode end |
#pid_file ⇒ Object
Returns the value of attribute pid_file.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def pid_file @pid_file end |
#port ⇒ Object
Returns the value of attribute port.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def port @port end |
#server ⇒ Object
Returns the value of attribute server.
20 21 22 |
# File 'lib/devserver/command_manager.rb', line 20 def server @server end |
Instance Method Details
#command(mode = self.mode) ⇒ String
returns command for @server and @mode (start, stop, debug)
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/devserver/command_manager.rb', line 104 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 |
#command_available? ⇒ Boolean
returns true/false if the gem corresponding to self.server is installed
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/devserver/command_manager.rb', line 120 def command_available? case self.server when 'passenger' gem_available?('passenger') when 'thin' gem_available?('thin') when 'mongrel' gem_available?('mongrel') else raise DevserverError, "Unrecognized web server: #{self.server}" 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/devserver/command_manager.rb', line 36 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
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/devserver/command_manager.rb', line 136 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
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/devserver/command_manager.rb', line 72 def start_command(mode = self.mode) case self.server when 'passenger' "passenger start #{self.(mode)}" when 'thin' "thin #{self.(mode)} start" when 'mongrel' "mongrel_rails start #{self.(mode)}" else raise DevserverError, "Unrecognized web server: #{self.server}" end end |
#start_devserver(mode = self.mode) ⇒ Object
152 153 154 155 156 |
# File 'lib/devserver/command_manager.rb', line 152 def start_devserver(mode = self.mode) if(self.command_available?) system("#{self.start_command(mode)}") end end |
#start_options(mode = self.mode) ⇒ String
builds the command options with regard to the specified server
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/devserver/command_manager.rb', line 51 def (mode = self.mode) = "--port #{self.port} --environment #{self.environment}" if(mode == 'debug') += " --debug" end case self.server when 'passenger' "#{} --log-file #{self.log_file} --pid-file #{self.pid_file}" when 'thin' "#{} --log #{self.log_file} --pid #{self.pid_file}" when 'mongrel' "#{} --log #{self.log_file} --pid #{self.pid_file}" else nil end end |
#stop_command ⇒ String
builds the stop command for @server
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/devserver/command_manager.rb', line 88 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
158 159 160 161 162 |
# File 'lib/devserver/command_manager.rb', line 158 def stop_devserver if(self.command_available?) system("#{self.stop_command}") end end |