Skip to content

Commit f8c8472

Browse files
committed
[Gem] Styling, refactor for elasticsearch Gem
1 parent e8d1fbc commit f8c8472

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

elasticsearch/Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ if ENV['TRANSPORT_VERSION'] == 'main'
3030
gem 'elastic-transport', git: 'https://github.com/elastic/elastic-transport-ruby.git', branch: 'main'
3131
end
3232

33-
if RUBY_VERSION >= '3.0'
34-
gem 'opentelemetry-sdk', require: false
35-
end
33+
gem 'opentelemetry-sdk', require: false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0')

elasticsearch/elasticsearch.gemspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
lib = File.expand_path('../lib', __FILE__)
18+
lib = File.expand_path('lib', __dir__)
1919
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2020
require 'elasticsearch/version'
2121

@@ -45,10 +45,9 @@ Gem::Specification.new do |s|
4545
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
4646
s.rdoc_options = ['--charset=UTF-8']
4747

48-
s.required_ruby_version = '>= 2.5'
49-
50-
s.add_dependency 'elastic-transport', '~> 8.3'
48+
s.required_ruby_version = '>= 2.6' # For compatibility with JRuby 9.3
5149
s.add_dependency 'elasticsearch-api', '9.0.0'
50+
s.add_dependency 'elastic-transport', '~> 8.3'
5251

5352
s.add_development_dependency 'base64'
5453
s.add_development_dependency 'bundler'

elasticsearch/lib/elasticsearch.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class Client
3737
#
3838
# @param [Hash] arguments - initializer arguments
3939
# @option arguments [String] :cloud_id - The Cloud ID to connect to Elastic Cloud
40-
# @option arguments [String, Hash] :api_key Use API Key Authentication, either the base64 encoding of `id` and `api_key`
41-
# joined by a colon as a String, or a hash with the `id` and `api_key` values.
40+
# @option arguments [String, Hash] :api_key Use API Key Authentication, either the base64 encoding of `id` and
41+
# `api_key` joined by a colon as a String, or a hash with the `id` and
42+
# `api_key` values.
4243
# @option arguments [String] :opaque_id_prefix set a prefix for X-Opaque-Id when initializing the client.
4344
# This will be prepended to the id you set before each request
4445
# if you're using X-Opaque-Id
@@ -65,10 +66,10 @@ def method_missing(name, *args, &block)
6566
opaque_id = @opaque_id_prefix ? "#{@opaque_id_prefix}#{opaque_id}" : opaque_id
6667
args[4] = headers.merge('X-Opaque-Id' => opaque_id)
6768
end
68-
unless @verified
69-
verify_elasticsearch(*args, &block)
70-
else
69+
if @verified
7170
@transport.perform_request(*args, &block)
71+
else
72+
verify_elasticsearch(*args, &block)
7273
end
7374
else
7475
@transport.send(name, *args, &block)
@@ -101,6 +102,7 @@ def verify_elasticsearch(*args, &block)
101102
raise e
102103
end
103104
raise Elasticsearch::UnsupportedProductError unless response.headers['x-elastic-product'] == 'Elasticsearch'
105+
104106
@verified = true
105107
response
106108
end
@@ -175,7 +177,7 @@ def set_user_agent!(arguments)
175177
end
176178
arguments[:transport_options] ||= {}
177179
arguments[:transport_options][:headers] ||= {}
178-
arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ')})
180+
arguments[:transport_options][:headers].merge!({ user_agent: user_agent.join('; ') })
179181
end
180182
end
181183

0 commit comments

Comments
 (0)