Class: ChefSearch::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/chefsearch/search.rb

Overview

Implements the searching

Constant Summary collapse

FILTER_RESULT =
{ name: ['name'] }

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Search

Returns a new instance of Search.



11
12
13
14
# File 'lib/chefsearch/search.rb', line 11

def initialize(config = nil)
  @config_filename = config
  @chef_config = load_config
end

Instance Method Details

#search(opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chefsearch/search.rb', line 16

def search(opts = {})
  name = opts.fetch(:name, '*')
  role = opts.fetch(:role, '*')
  chef_environment = opts.fetch(:chef_environment, '*')

  query = build_query(name, role, chef_environment)
  ChefSearch.logger.debug { query }

  results = Chef::Search::Query.new.search(:node,
                                           query,
                                           filter_result: FILTER_RESULT
                                           )
  parse_results(results)
end