From 196dff55921c28e2685f072c1c03db27fac97751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Batista?= Date: Fri, 14 Mar 2014 12:01:07 -0300 Subject: [PATCH] Use array instead of splat on search initializer --- lib/mongoid/giza.rb | 2 +- lib/mongoid/giza/search.rb | 8 ++++---- spec/mongoid/giza/search_spec.rb | 2 +- spec/mongoid/giza_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/mongoid/giza.rb b/lib/mongoid/giza.rb index 72284d4..64af5f0 100644 --- a/lib/mongoid/giza.rb +++ b/lib/mongoid/giza.rb @@ -128,7 +128,7 @@ def process_dynamic_sphinx_index(dynamic_index) # @return [Array] an Array with Riddle result hashes containing an additional key with the name of the class. # The value of this aditional key is a Mongoid::Criteria that return the actual objects of the match def search(&block) - search = Mongoid::Giza::Search.new(giza_configuration.searchd.address, giza_configuration.searchd.port, *sphinx_indexes_names) + search = Mongoid::Giza::Search.new(giza_configuration.searchd.address, giza_configuration.searchd.port, sphinx_indexes_names) Docile.dsl_eval(search, &block) results = search.run results.each { |result| result[name.to_sym] = self.in(giza_id: result[:matches].map { |match| match[:doc] }) } diff --git a/lib/mongoid/giza/search.rb b/lib/mongoid/giza/search.rb index e8343ac..5ec009d 100644 --- a/lib/mongoid/giza/search.rb +++ b/lib/mongoid/giza/search.rb @@ -10,11 +10,11 @@ class Search # # @param host [String] the host address of sphinxd # @param port [Fixnum] the TCP port of sphinxd - # @param indexes [String] an optional string define the indexes that the search will run on. - # Defaults to "*" which means all indexes - def initialize(host, port, *indexes) + # @param names [Array] an optional array defining the indexes that the search will run on. + # Defaults to "[]" which means all indexes + def initialize(host, port, names = []) @client = Riddle::Client.new(host, port) - @indexes = indexes + @indexes = names end # Sets the search criteria on full-text fields diff --git a/spec/mongoid/giza/search_spec.rb b/spec/mongoid/giza/search_spec.rb index 0090a9c..158b549 100644 --- a/spec/mongoid/giza/search_spec.rb +++ b/spec/mongoid/giza/search_spec.rb @@ -24,7 +24,7 @@ end it "should accept a index list" do - indexes = Mongoid::Giza::Search.new("localhost", 9132, :index1, :index2).indexes + indexes = Mongoid::Giza::Search.new("localhost", 9132, [:index1, :index2]).indexes expect(indexes).to eql([:index1, :index2]) end end diff --git a/spec/mongoid/giza_spec.rb b/spec/mongoid/giza_spec.rb index 0408e36..1c2fd3a 100644 --- a/spec/mongoid/giza_spec.rb +++ b/spec/mongoid/giza_spec.rb @@ -28,7 +28,7 @@ class Person let(:search) do search = double("search") - allow(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132) { search } + allow(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, []) { search } search end @@ -145,7 +145,7 @@ class Person end it "should create a search" do - expect(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, :Person, :Person_2) { double("search").as_null_object } + expect(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, [:Person, :Person_2]) { double("search").as_null_object } Person.sphinx_index { } Person.sphinx_index { name :Person_2 } Person.search { }