-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danil Nurgaliev
committed
Jan 11, 2024
1 parent
c02564d
commit 636339a
Showing
7 changed files
with
59 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Chewy | ||
# Replacement for Chewy.client | ||
class ElasticClient | ||
def self.build_es_client(configuration = Chewy.configuration) | ||
client_configuration = configuration.deep_dup | ||
client_configuration.delete(:prefix) # used by Chewy, not relevant to Elasticsearch::Client | ||
block = client_configuration[:transport_options].try(:delete, :proc) | ||
::Elasticsearch::Client.new(client_configuration, &block) | ||
end | ||
|
||
def initialize(elastic_client) | ||
@elastic_client = elastic_client || self.class.build_es_client | ||
end | ||
|
||
def method_missing(name, *args, **kwargs, &block) | ||
inspect_payload(name, args, kwargs) | ||
|
||
@elastic_client.__send__(name, *args, **kwargs, &block) | ||
end | ||
|
||
def respond_to_missing?(name, _include_private = false) | ||
@elastic_client.respond_to?(name) || super | ||
end | ||
|
||
def inspect_payload(name, args, kwargs) | ||
Chewy.config.before_es_request_filter&.call(name, args, kwargs) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Before search request filter' do | ||
let(:filter) { instance_double('Proc') } | ||
let!(:filter_previous_value) { Chewy.before_es_request_filter } | ||
|
||
before do | ||
Chewy.before_es_request_filter = filter | ||
end | ||
|
||
after do | ||
Chewy.before_es_request_filter = filter_previous_value | ||
end | ||
|
||
it 'call filter with the request body' do | ||
expect(filter).to receive(:call).with(:search, [{body: {size: 0}, index: ['products']}], {}) | ||
Chewy.client.search({index: ['products'], body: {size: 0}}).to_a | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters