I encountered a problem about using "search" method in library code: libraries/helpers.rb
Bcpc
Helper
extend self
def help(node=node)
search(:node, "....")
end
end
end
Chef::Recipe.send(:include, Bcpc::Helper)
Chef::Resource.send(:include, Bcpc::Helper) for the recipes using module methods.
Then use this module method in recipes like this: Bcpc::Helper.help(node) When I run it, it report the error that search method is not defined in Bcpc::Helper:Module
I found the search method is defined in Chef::Search::Query class. Then I tried use the full name of search in my library code like: Chef::Search::Query.search(:node, "...."). But it reported search is undefined in Chef::Search::Query. Should this search method be a static method that can be called with its class name?
How can I use the Chef provided "search" method in my library code in this case? Thanks!
You want something like this.
Chef::Search::Query.new.search(:node, 'foo:bar') do |n|
# something with n
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With