Skip to content

Commit ef6b019

Browse files
committed
Fix linter problems
1 parent e67fe25 commit ef6b019

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

lib/meilisearch/rails/multi_search/result.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def initialize(searches, raw_results)
2323

2424
include Enumerable
2525

26-
def each_hit
26+
def each_hit(&block)
2727
@results.each do |_index_target, results|
28-
results.each { |res| yield res }
28+
results.each(&block)
2929
end
3030
end
31-
alias_method :each, :each_hit
31+
alias each each_hit
3232

3333
def each_result
3434
@results.each
@@ -37,20 +37,18 @@ def each_result
3737
def to_a
3838
@results.values.flatten(1)
3939
end
40-
alias_method :to_ary, :to_a
40+
alias to_ary to_a
4141

4242
def to_h
4343
@results
4444
end
45-
alias_method :to_hash, :to_h
45+
alias to_hash to_h
4646

4747
private
4848

4949
def load_results(klass, result)
5050
pk_method = klass.ms_primary_key_method
51-
pk_method = pk_method.in if Utilities.is_mongo_model?(klass)
52-
53-
ms_pk = klass.meilisearch_options[:primary_key] || IndexSettings::DEFAULT_PRIMARY_KEY
51+
pk_method = pk_method.in if Utilities.mongo_model?(klass)
5452

5553
condition_key = pk_is_virtual?(klass, pk_method) ? klass.primary_key : pk_method
5654

@@ -78,8 +76,8 @@ def load_results(klass, result)
7876

7977
def pk_is_virtual?(model_class, pk_method)
8078
model_class.columns
81-
.map(&(Utilities.is_sequel_model?(model_class) ? :to_s : :name))
82-
.exclude?(pk_method.to_s)
79+
.map(&(Utilities.sequel_model?(model_class) ? :to_s : :name))
80+
.exclude?(pk_method.to_s)
8381
end
8482
end
8583
end

lib/meilisearch/rails/utilities.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def indexable?(record, options)
4848
true
4949
end
5050

51-
def is_mongo_model?(model_class)
51+
def mongo_model?(model_class)
5252
defined?(::Mongoid::Document) && model_class.include?(::Mongoid::Document)
5353
end
5454

55-
def is_sequel_model?(model_class)
55+
def sequel_model?(model_class)
5656
defined?(::Sequel::Model) && model_class < Sequel::Model
5757
end
5858

spec/multi_search/result_spec.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
require 'spec_helper'
22

3-
describe MeiliSearch::Rails::MultiSearchResult do
4-
it 'is enumerable' do
5-
expect(described_class).to include(Enumerable)
6-
end
7-
3+
describe MeiliSearch::Rails::MultiSearchResult do # rubocop:todo RSpec/FilePath
84
let(:raw_results) do
95
[
106
{ 'indexUid' => 'books_index',
117
'hits' => [{ 'name' => 'Steve Jobs', 'id' => '3', 'author' => 'Walter Isaacson', 'premium' => nil, 'released' => nil, 'genre' => nil }],
12-
'query' => 'Steve', 'processingTimeMs' => 0, 'limit' => 20, 'offset' => 0, 'estimatedTotalHits' => 1
13-
},
8+
'query' => 'Steve', 'processingTimeMs' => 0, 'limit' => 20, 'offset' => 0, 'estimatedTotalHits' => 1 },
149
{ 'indexUid' => 'products_index',
1510
'hits' => [{ 'id' => '4', 'href' => 'ebay', 'name' => 'palm pixi plus' }],
16-
'query' => 'palm', 'processingTimeMs' => 0, 'limit' => 1, 'offset' => 0, 'estimatedTotalHits' => 2
17-
},
11+
'query' => 'palm', 'processingTimeMs' => 0, 'limit' => 1, 'offset' => 0, 'estimatedTotalHits' => 2 },
1812
{ 'indexUid' => 'color_index',
1913
'hits' => [
2014
{ 'name' => 'black', 'id' => '5', 'short_name' => 'bla', 'hex' => 0 },
2115
{ 'name' => 'blue', 'id' => '4', 'short_name' => 'blu', 'hex' => 255 }
2216
],
23-
'query' => 'bl', 'processingTimeMs' => 0, 'limit' => 20, 'offset' => 0, 'estimatedTotalHits' => 2
24-
}
17+
'query' => 'bl', 'processingTimeMs' => 0, 'limit' => 20, 'offset' => 0, 'estimatedTotalHits' => 2 }
2518
]
2619
end
2720

21+
it 'is enumerable' do
22+
expect(described_class).to include(Enumerable)
23+
end
24+
2825
context 'with index name keys' do
2926
subject(:result) { described_class.new(searches, raw_results) }
3027

@@ -48,13 +45,16 @@
4845
it 'enumerates through the hits of each result with #each_result' do
4946
expect(result.each_result).to be_an(Enumerator)
5047
expect(result.each_result).to contain_exactly(
51-
[ 'books_index', contain_exactly(
52-
a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')) ],
53-
[ 'products_index', contain_exactly(
54-
a_hash_including('name' => 'palm pixi plus')) ],
55-
[ 'color_index', contain_exactly(
56-
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
57-
a_hash_including('name' => 'black', 'short_name' => 'bla')) ]
48+
['books_index', contain_exactly(
49+
a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')
50+
)],
51+
['products_index', contain_exactly(
52+
a_hash_including('name' => 'palm pixi plus')
53+
)],
54+
['color_index', contain_exactly(
55+
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
56+
a_hash_including('name' => 'black', 'short_name' => 'bla')
57+
)]
5858
)
5959
end
6060

@@ -69,7 +69,7 @@
6969
end
7070

7171
it 'aliases as #to_ary' do
72-
expect(subject.method(:to_ary).original_name).to eq :to_a
72+
expect(result.method(:to_ary).original_name).to eq :to_a
7373
end
7474
end
7575

0 commit comments

Comments
 (0)