兼容ruby 1.9

sw_new_course
guange 10 years ago
parent 2f86874c6c
commit 8da9805bcc

@ -19,14 +19,25 @@ module Grack
# _Not_ the same as `IO.popen(...).read` # _Not_ the same as `IO.popen(...).read`
# By using a block we tell IO.popen to close (wait for) the child process # By using a block we tell IO.popen to close (wait for) the child process
# after we are done reading its output. # after we are done reading its output.
IO.popen(popen_env, cmd, popen_options) { |p| p.read } if RUBY_VERSION.start_with?("2")
IO.popen(popen_env, cmd, popen_options) { |p| p.read }
else
IO.popen(cmd, popen_options) { |p| p.read }
end
end end
def execute(cmd) def execute(cmd)
cmd = command(cmd) cmd = command(cmd)
if block_given? if block_given?
IO.popen(popen_env, cmd, File::RDWR, popen_options) do |pipe|
yield(pipe) if RUBY_VERSION.start_with?("2")
IO.popen(popen_env, cmd, File::RDWR, popen_options) do |pipe|
yield(pipe)
end
else
IO.popen(cmd, File::RDWR, popen_options) do |pipe|
yield(pipe)
end
end end
else else
capture(cmd).chomp capture(cmd).chomp
@ -61,9 +72,11 @@ module Grack
match = execute(%W(rev-parse --git-dir)).match(/\.$|\.git$/) match = execute(%W(rev-parse --git-dir)).match(/\.$|\.git$/)
if match.to_s == '.git' if RUBY_VERSION.start_with?("2")
# Since the parent could be a git repo, we want to make sure the actual repo contains a git dir. if match.to_s == '.git'
return false unless Dir.entries(repo).include?('.git') # Since the parent could be a git repo, we want to make sure the actual repo contains a git dir.
return false unless Dir.entries(repo).include?('.git')
end
end end
match match

Loading…
Cancel
Save