Module containing various helper methods useful for most commands.
@author Yorick Peterse @author TJ Vanderpoel @since 21-07-2011
Checks if the specified PID points to a process that’s already running.
@author TJ Vanderpoel @since 21-07-2011 @param [String] pid The path to the PID. @return [TrueClass|FalseClass]
# File lib/ramaze/bin/helper.rb, line 20 20: def is_running?(pid) 21: return false if !File.exist?(pid) 22: 23: pid = File.read(pid).to_i 24: 25: if is_windows? 26: wmi = WIN32OLE.connect("winmgmts://") 27: processes, ours = wmi.ExecQuery( 28: "select * from win32_process where ProcessId = #{pid}" 29: ), [] 30: 31: processes.each { |process| ours << process.Name } 32: 33: return ours.first.nil? 34: else 35: begin 36: prio = Process.getpriority(Process::PRIO_PROCESS, pid) 37: return true 38: rescue Errno::ESRCH 39: return false 40: end 41: end 42: end
Checks if the system the user is using is Windows.
@author TJ Vanderpoel @since 21-07-2011 @return [TrueClass|FalseClass]
# File lib/ramaze/bin/helper.rb, line 51 51: def is_windows? 52: return @is_win if @is_win 53: 54: begin; require "win32ole"; rescue LoadError; end 55: 56: @is_win ||= Object.const_defined?("WIN32OLE") 57: end
Tries to extract the path to the Rackup executable.
@author TJ Vanderpoel @since 21-07-2001 @return [String]
# File lib/ramaze/bin/helper.rb, line 66 66: def rackup_path 67: return @rackup_path if @rackup_path 68: 69: # Check with 'which' on platforms which support it 70: unless is_windows? 71: @rackup_path = %{which rackup}.to_s.chomp 72: 73: if @rackup_path.size > 0 and File.file?(@rackup_path) 74: return @rackup_path 75: end 76: end 77: 78: # check for rackup in RUBYLIB 79: libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":") 80: 81: if rack_lib = libs.detect { |r| r.match %<(\\|/)rack\11>> } 82: require "pathname" 83: @rackup_path = Pathname.new(rack_lib).parent.join("bin").join( 84: "rackup" 85: ).expand_path 86: 87: return @rackup_path if File.file?(@rackup_path) 88: end 89: 90: begin 91: require "rubygems" 92: require "rack" 93: require "pathname" 94: 95: @rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s 96: 97: return @rackup_path if File.file?(@rackup_path) 98: rescue LoadError 99: nil 100: end 101: 102: @rackup_path = nil 103: abort "Cannot find the path to the Rackup executable" 104: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.