Module: Ramaze::Tool::Bin::Helpers
- Included in:
- Cmd
- Defined in:
- lib/ramaze/tool/bin.rb
Overview
Helper methods {{{
Instance Method Summary collapse
-
#check_running?(pid_file) ⇒ Boolean
}}}.
-
#default_pidfile ⇒ Object
{{{.
-
#find_pid(pid_file) ⇒ Object
}}}.
-
#is_running?(pid) ⇒ Boolean
}}}.
-
#is_windows? ⇒ Boolean
We’re really only concerned about win32ole, so we focus our check on its ability to load that.
-
#rackup_path ⇒ Object
Find the path to rackup, by searching for -R (undocumented cli argument), then checking RUBYLIB for the first rack it can find there, finally falling back to gems and looking for rackup in the gem bindir.
Instance Method Details
#check_running?(pid_file) ⇒ Boolean
}}}
86 87 88 89 |
# File 'lib/ramaze/tool/bin.rb', line 86 def check_running?(pid_file) # {{{ return false unless File.file?(pid_file) is_running?(File.read(pid_file).to_i) end |
#default_pidfile ⇒ Object
{{{
10 11 12 13 14 |
# File 'lib/ramaze/tool/bin.rb', line 10 def default_pidfile # {{{ return @default_pidfile if @default_pidfile require "pathname" @default_pidfile = (Pathname.new(".")..basename.to_s + ".pid").strip end |
#find_pid(pid_file) ⇒ Object
}}}
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ramaze/tool/bin.rb', line 91 def find_pid(pid_file) # {{{ if pid_file.nil? or not File.file?(pid_file) pid_file = default_pidfile end unless File.file?(pid_file) $stderr.puts "Could not find running process id." return false end pid_file end |
#is_running?(pid) ⇒ Boolean
}}}
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ramaze/tool/bin.rb', line 70 def is_running?(pid) # {{{ if is_windows? wmi = WIN32OLE.connect("winmgmts://") processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), [] processes.each { |process| ours << process.Name } ours.first.nil? else begin prio = Process.getpriority(Process::PRIO_PROCESS, pid) true rescue Errno::ESRCH false end end end |
#is_windows? ⇒ Boolean
We’re really only concerned about win32ole, so we focus our check on its ability to load that
18 19 20 21 22 23 24 25 |
# File 'lib/ramaze/tool/bin.rb', line 18 def is_windows? # {{{ return @is_win if @is_win begin require "win32ole" rescue LoadError end @is_win ||= Object.const_defined?("WIN32OLE") end |
#rackup_path ⇒ Object
Find the path to rackup, by searching for -R (undocumented cli argument), then checking RUBYLIB for the first rack it can find there, finally falling back to gems and looking for rackup in the gem bindir. If we can’t find rackup we’re raising; not even #usage is sane without rackup.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ramaze/tool/bin.rb', line 32 def rackup_path # {{{ return @rackup_path if @rackup_path # Use the supplied path if the user supplied -R if path_supplied = ARGV.delete("-R") @rackup_path = ARGV.delete(@ourargs[@ourargs.index("-R") + 1]) if @rackup_path and File.file?(@rackup_path) return @rackup_path else $stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)" end end # Check with 'which' on platforms which support it unless is_windows? @rackup_path = %x{which rackup}.to_s.chomp if @rackup_path.size > 0 and File.file?(@rackup_path) return @rackup_path end end # check for rackup in RUBYLIB libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":") if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> } require "pathname" @rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup"). return @rackup_path if File.file?(@rackup_path) end begin require "rubygems" require "rack" require "pathname" @rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s return @rackup_path if File.file?(@rackup_path) rescue LoadError nil end @rackup_path = nil raise "Cannot find path to rackup, please supply full path to rackup with -R" end |