Class: Chef::Search::Query
- Inherits:
-
Object
- Object
- Chef::Search::Query
- Defined in:
- lib/chef/search/query.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#rest ⇒ Object
Returns the value of attribute rest.
Instance Method Summary collapse
-
#initialize(url = nil, config: Chef::Config) ⇒ Query
constructor
A new instance of Query.
-
#partial_search(type, query = '*:*', *args, &block) ⇒ Object
Backwards compatability for cookbooks.
-
#search(type, query = '*:*', *args, &block) ⇒ Object
New search input, designed to be backwards compatible with the old method signature ‘type’ and ‘query’ are the same as before, args now will accept either a Hash of search arguments with symbols as the keys (ie :sort, :start, :rows) and a :filter_result option.
Constructor Details
#initialize(url = nil, config: Chef::Config) ⇒ Query
32 33 34 35 |
# File 'lib/chef/search/query.rb', line 32 def initialize(url=nil, config:Chef::Config) @config = config @url = url end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
30 31 32 |
# File 'lib/chef/search/query.rb', line 30 def config @config end |
#rest ⇒ Object
Returns the value of attribute rest.
29 30 31 |
# File 'lib/chef/search/query.rb', line 29 def rest @rest end |
Instance Method Details
#partial_search(type, query = '*:*', *args, &block) ⇒ Object
Backwards compatability for cookbooks. This can be removed in Chef > 12.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/search/query.rb', line 43 def partial_search(type, query='*:*', *args, &block) Chef::Log.warn("DEPRECATED: The 'partial_search' API is deprecated and will be removed in\nfuture releases. Please use 'search' with a :filter_result argument to get\npartial search data.\n") if !args.empty? && args.first.is_a?(Hash) # partial_search uses :keys instead of :filter_result for # result filtering. args_h = args.first.dup args_h[:filter_result] = args_h[:keys] args_h.delete(:keys) search(type, query, args_h, &block) else search(type, query, *args, &block) end end |
#search(type, query = '*:*', *args, &block) ⇒ Object
New search input, designed to be backwards compatible with the old method signature ‘type’ and ‘query’ are the same as before, args now will accept either a Hash of search arguments with symbols as the keys (ie :sort, :start, :rows) and a :filter_result option.
:filter_result should be in the format of another Hash with the structure of:
:returned_name1 => ["path", "to", "variable"],
:returned_name2 => ["shorter", "path"]
a real world example might be something like:
:ip_address => ["ipaddress"],
:ruby_version => ["languages", "ruby", "version"]
this will bring back 2 variables 'ip_address' and 'ruby_version' with whatever value was found
an example of the returned json may be: “ruby_version”: “1.9.3”
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chef/search/query.rb', line 83 def search(type, query='*:*', *args, &block) validate_type(type) args_h = hashify_args(*args) response = call_rest_service(type, query: query, **args_h) if block response["rows"].each { |row| block.call(row) if row } unless (response["start"] + response["rows"].length) >= response["total"] args_h[:start] = response["start"] + (args_h[:rows] || 0) search(type, query, args_h, &block) end true else [ response["rows"], response["start"], response["total"] ] end end |