How to use the "cook" search method in library code (in the modular method)?

I had a problem using the search method in the 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 recipes using modular methods.

Then use this module method in recipes, for example: BCPC :: Helper.help (node) When I run it, it reports an error that the search method is not defined in Bcpc :: Helper: Module

I found that the search method is defined in the Chef :: Search :: Query class. Then I tried to use the full search name in my library code, for example: Chef :: Search :: Query.search (: node, "...."). But he said that the 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 Chef provided that the search method in my library code is in this case? Thank!

+4
source share
1 answer

You want something like this.

Chef::Search::Query.new.search(:node, 'foo:bar') do |n|
  # something with n
end
+5
source

Source: https://habr.com/ru/post/1570925/


All Articles