NOTE: the question was edited to reflect the issue.
i would like to work with knife-api
rubygem. enclosed a snippet of my code
require 'chef'
require 'chef/knife'
require 'knife/api'
module X
module Y
module Z
include Chef::Knife::API
def self.foo
resp = knife_capture :search, ['*:*']
puts resp
end
end
end
end
when X::Y::Z.foo
is called, it returns
gems/knife-api-0.1.7/lib/knife/api.rb:41:in `ensure in knife_capture': undefined local variable or method `revert_io_channels' for X::Y::Z (NameError)
it appears that he enclosing scope functions (Chef::Knife
within knife-api
) are inaccessible within X::Y::Z.foo
.
how should i make this work?
In a complete non-answer, do not use the knife-api
gem. It should not exist. The correct gem to use if you want to access Chef API data from Ruby code is chef-api
(I know, we're real creative with names). If you want to do something very small, check out the knife exec
command which just exposes the raw Chef object API (not as refined as chef-api
, but built in).