lib/ridley/resources/search_resource.rb
# Executes the built up query on the search's client
#
# @param [#to_sym, #to_s] index
# @param [#to_s] query_string
#
# @option options [String] :sort
#   a sort string such as 'name DESC'
# @option options [Integer] :rows
#   how many rows to return
# @option options [Integer] :start
#   the result number to start from
#
# @example
#   Search.new(client, :role)
#   search.run =>
#     {
#       total: 1,
#       start: 0,
#       rows: [
#         {
#           name: "ridley-test-role",
#           default_attributes: {},
#           json_class: "Chef::Role",
#           env_run_lists: {},
#           run_list: [],
#           description: "a test role for Ridley!",
#           chef_type: "role",
#           override_attributes: {}
#         }
#       ]
#     }
#
# @return [Array<ChefObject>, Hash]
Executes the built up query on the search's client
Executes the built up query on the search ' s client
def run(index, query_string, resources_registry, options = {})
      query_uri = self.class.query_uri(index)
      query     = self.class.build_query(query_string, options)
      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
def run ( index , query_string , resources_registry , options = { } ) query_uri = self . class . query_uri ( index ) query = self . class . build_query ( query_string , options ) 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
Executes the built up query on the search's client
Executes the built up query on the search ' s client
None
Array<ChefObject>, Hash
index
<not_specific>
query_string
<not_specific>
resources_registry
<not_specific>
options
:start the result number to start from
: start the result number to start from
<not_specific>
None
example
Search.new(client, :role) search.run => { total: 1, start: 0, rows: [ { name: "ridley-test-role", default_attributes: {}, json_class: "Chef::Role", env_run_lists: {}, run_list: [], description: "a test role for Ridley!", chef_type: "role", override_attributes: {} } ] }
Search . new ( client : role ) search . run = > { total : 1 start : 0 rows : [ { name : " ridley - test - role " default_attributes : {} json_class : " Chef :: Role " env_run_lists : {} run_list : [] description : " a test role for Ridley! " chef_type : " role " override_attributes : {} } ] }