兼容ruby 1.9

This commit is contained in:
guange 2015-07-02 20:10:52 +08:00
parent 2f86874c6c
commit 8da9805bcc
1 changed files with 19 additions and 6 deletions

View File

@ -19,14 +19,25 @@ module Grack
# _Not_ the same as `IO.popen(...).read`
# By using a block we tell IO.popen to close (wait for) the child process
# 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
def execute(cmd)
cmd = command(cmd)
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
else
capture(cmd).chomp
@ -61,9 +72,11 @@ module Grack
match = execute(%W(rev-parse --git-dir)).match(/\.$|\.git$/)
if match.to_s == '.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')
if RUBY_VERSION.start_with?("2")
if match.to_s == '.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
match