Class: Ridley::SearchResource
- Defined in:
- lib/ridley/resources/search_resource.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#indexes ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on.
-
#run(index, query_string, resources_registry, options = {}) ⇒ Array<ChefObject>, Hash
Executes the built up query on the search’s client.
Methods inherited from Resource
#all, #connection, #create, #delete, #delete_all, #find, #initialize, #new, representation, represented_by, resource_path, set_resource_path, #update
Constructor Details
This class inherits a constructor from Ridley::Resource
Class Method Details
.build_query(query_string, options = {}) ⇒ Hash
14 15 16 17 18 19 20 21 |
# File 'lib/ridley/resources/search_resource.rb', line 14 def build_query(query_string, = {}) {}.tap do |query_opts| query_opts[:q] = query_string unless query_string.nil? query_opts[:sort] = [:sort] unless [:sort].nil? query_opts[:rows] = [:rows] unless [:rows].nil? query_opts[:start] = [:start] unless [:start].nil? end end |
.query_uri(index) ⇒ String
26 27 28 |
# File 'lib/ridley/resources/search_resource.rb', line 26 def query_uri(index) "#{resource_path}/#{index}" end |
Instance Method Details
#indexes ⇒ Array<String, Symbol>
Returns an array of possible search indexes to be search on
42 43 44 |
# File 'lib/ridley/resources/search_resource.rb', line 42 def indexes request(:get, self.class.resource_path).collect { |name, _| name } end |
#run(index, query_string, resources_registry, options = {}) ⇒ Array<ChefObject>, Hash
Executes the built up query on the search’s client
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ridley/resources/search_resource.rb', line 79 def run(index, query_string, resources_registry, = {}) query_uri = self.class.query_uri(index) query = self.class.build_query(query_string, ) response = request(:get, query_uri, query) case index.to_sym when :node response[:rows].collect { |row| Ridley::NodeObject.new(resources_registry[:node_resource], row) } when :role response[:rows].collect { |row| Ridley::RoleObject.new(resources_registry[:role_resource], row) } when :client response[:rows].collect { |row| Ridley::ClientObject.new(resources_registry[:client_resource], row) } when :environment response[:rows].collect { |row| Ridley::EnvironmentObject.new(resources_registry[:environment_resource], row) } else response[:rows] end end |