2012-09-21 46 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文章更多信息