2012-09-21 50 views
1

在Opscode公司的Wiki有有下列文件:如何使用ohai宝石

require 'ohai' 

# ... 
# Profit! ;-) 

如何我可以打印由“ohai”的命令,但使用IRB提供的JSON数据?我试图看到application.rb中的代码,但我得到空的数据。

require 'ohai/application' 
ohai = Ohai::System.new 
ohai.json_pretty_print 
=> "{\n\n}" 

试图内厨师(或Shef)做到这一点,我只是想用ohai宝石本身,在我自己的应用程序。

回答

6

关于戳在Ohai::Application类(当您运行ohai你会得到什么),#run_application实例Ohai::System,除非它是由一个配置文件,它调用all_plugins用数据来填充它。

推测地,Ohai::System#all_plugins将数据收集委托给the lib/ohai/plugins directory

$ irb -rohai 
> system = Ohai::System.new 
=> #<Ohai::System:0x00000100988950 @data={}, @seen_plugins={}, @providers={}, @plugin_path="", @hints={}> 
> system.all_plugins 
=> true 
> puts system.to_json 
{"languages":{"ruby":{"platform":"x86_64-darwin10.8.0","version":"1.9.2", ... 
> system.to_json.size 
=> 42395 
2

我也搜索了一个简单而良好的图书馆这样做...

我碰到

Usagewatch

,并在5分钟后有我的监视。 rb done ..

安装:gem install usagewatch

在Mac上安装:创业板安装usagewatch_ext

参考this文章更多信息