有没有办法验证
Ruby程序内部是否有最新版本的gem?也就是说,有没有办法通过编程方式来捆绑过时的#{gemname}?
我试着看着bundler的源代码,但我找不到一个直接的方式.目前我正在做这件事,这是脆弱,缓慢,如此不善:
IO.popen(%w{/usr/bin/env bundle outdated gemname}) do |proc| output = proc.readlines.join("\n") return output.include?("Your bundle is up to date!") end
解决方法
避免外部执行的一种方法:
对于Bundler 1.2.x
require 'bundler/cli' # intercepting $stdout into a StringIO old_stdout,$stdout = $stdout,StringIO.new # running the same code run in the 'bundler outdated' utility Bundler::CLI.new.outdated('rails') # storing the output output = $stdout.string # restoring $stdout $stdout = old_stdout
对于bundler 1.3.x
require 'bundler/cli' require 'bundler/friendly_errors' # let's cheat the CLI class with fake exit method module Bundler class CLI desc 'exit','fake exit' # this is required by Thor def exit(*); end # simply do nothing end end # intercepting $stdout into a StringIO old_stdout,StringIO.new # running the same code run in the 'bundler outdated' utility Bundler.with_friendly_errors { Bundler::CLI.start(['outdated','rails']) } # storing the output output = $stdout.string # restoring $stdout $stdout = old_stdout
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。