我在库代码中使用"search"方法遇到了一个问题:libraries/helpers.rb
Bcpc
Helper
extend self
def help(node=node)
search(:node, "....")
end
end
end
Chef::Recipe.send(:include, Bcpc::Helper)
Run Code Online (Sandbox Code Playgroud)
使用模块方法的食谱的Chef :: Resource.send(:include,Bcpc :: Helper).
然后在这样的配方中使用此模块方法:Bcpc :: Helper.help(node)当我运行它时,它报告错误,即未在Bcpc :: Helper中定义搜索方法:模块
我发现搜索方法是在Chef :: Search :: Query类中定义的.然后我尝试在我的库代码中使用搜索的全名,例如:Chef :: Search :: Query.search(:node,"....").但它报告在Chef :: Search :: Query中未定义搜索.此搜索方法是否应该是可以使用其类名调用的静态方法?
在这种情况下,如何在库代码中使用Chef提供的"搜索"方法?谢谢!
你想要这样的东西.
Chef::Search::Query.new.search(:node, 'foo:bar') do |n|
# something with n
end
Run Code Online (Sandbox Code Playgroud)