从Ruby内部验证捆绑包的gem版本
发布时间:2020-12-16 22:22:38 所属栏目:百科 来源:网络整理
导读:有没有办法验证 Ruby程序内部是否有最新版本的gem?也就是说,有没有办法通过编程方式来捆绑过时的#{gemname}? 我试着看着bundler的源代码,但我找不到一个直接的方式.目前我正在做这件事,这是脆弱,缓慢,如此不善: IO.popen(%w{/usr/bin/env bundle outdated
有没有办法验证
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – Ruby – 如何从ruby上的.pfx文件中提取pu
- iphone – CLLocation distanceFromLocation
- PostgreSQL 硬件性能调整
- ruby-on-rails – apache说我的DocumentRoot目录不存在
- Ruby pre-1.9和Ruby 1.9线程之间有什么实际区别吗?
- c# – RestSharp – 如何处理非200响应? RestClient在Exec
- c – 我的班级干扰了库类
- 直接从Ruby中的单个元素哈希获取键或值
- .net – 如何基于多态清晰地处理不同的行为
- C++ partial_sort(STL partial_sort)排序算法详解