Skip to content

Commit

Permalink
Merge pull request #288 from github/fix-rubocop
Browse files Browse the repository at this point in the history
Fix RuboCop warnings and default Ruby version
  • Loading branch information
ndonewar authored Dec 6, 2023
2 parents 02cd7ce + 59ef81f commit 520c8d8
Show file tree
Hide file tree
Showing 27 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2']
ruby-version: ['3.2']
ES_VERSION: ['5.6.15', '8.7.0']
include:
- ES_VERSION: '5.6.15'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
ruby-version: '3.2'
bundler-cache: true
- run: bundle exec rubocop
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/vendor/gems
/.bundle
/.rbenv-version
/.ruby-version
/vendor/cache/*.gem
/coverage
Gemfile.lock
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
12 changes: 6 additions & 6 deletions lib/elastomer_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def initialize(host: "localhost", port: 9200, url: nil,
# fashion.
def dup
self.class.new \
url: url,
read_timeout: read_timeout,
open_timeout: open_timeout,
url:,
read_timeout:,
open_timeout:,
adapter: @adapter,
opaque_id: @opaque_id,
max_request_size: max_request_size,
max_request_size:,
basic_auth: @basic_auth,
token_auth: @token_auth
end
Expand Down Expand Up @@ -144,8 +144,8 @@ def connection
conn.use(:gzip)
conn.request(:encode_json)
conn.request(:opaque_id) if @opaque_id
conn.request(:limit_size, max_request_size: max_request_size) if max_request_size
conn.request(:elastomer_compress, compression: compression) if compress_body
conn.request(:limit_size, max_request_size:) if max_request_size
conn.request(:elastomer_compress, compression:) if compress_body

conn.options[:timeout] = read_timeout
conn.options[:open_timeout] = open_timeout
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/client/bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def bulk(body = nil, params = nil)
else
raise "bulk request body cannot be nil" if body.nil?
params ||= {}
updated_params = params.merge(body: body, action: "bulk", rest_api: "bulk")
updated_params = params.merge(body:, action: "bulk", rest_api: "bulk")
updated_params.delete(:type) if version_support.es_version_8_plus?

response = self.post "{/index}{/type}/_bulk", updated_params
Expand Down
6 changes: 3 additions & 3 deletions lib/elastomer_client/client/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_settings(params = {})
#
# Returns the response as a Hash
def update_settings(body, params = {})
response = client.put "/_cluster/settings", params.merge(body: body, action: "cluster.update_settings", rest_api: "cluster.put_settings")
response = client.put "/_cluster/settings", params.merge(body:, action: "cluster.update_settings", rest_api: "cluster.put_settings")
response.body
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def reroute(commands, params = {})
body = {commands: Array(commands)}
end

response = client.post "/_cluster/reroute", params.merge(body: body, action: "cluster.reroute", rest_api: "cluster.reroute")
response = client.post "/_cluster/reroute", params.merge(body:, action: "cluster.reroute", rest_api: "cluster.reroute")
response.body
end

Expand Down Expand Up @@ -217,7 +217,7 @@ def update_aliases(actions, params = {})
body = {actions: Array(actions)}
end

response = client.post "/_aliases", params.merge(body: body, action: "cluster.update_aliases", rest_api: "indices.update_aliases")
response = client.post "/_aliases", params.merge(body:, action: "cluster.update_aliases", rest_api: "indices.update_aliases")
response.body
end

Expand Down
12 changes: 6 additions & 6 deletions lib/elastomer_client/client/docs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def update_by_query(query, params = nil)
#
# Returns the response body as a Hash
def percolate(body, params = {})
response = client.get "/{index}/{type}{/id}/_percolate", update_params(params, body: body, action: "percolator.percolate", rest_api: "percolate")
response = client.get "/{index}/{type}{/id}/_percolate", update_params(params, body:, action: "percolator.percolate", rest_api: "percolate")
response.body
end

Expand All @@ -326,7 +326,7 @@ def percolate(body, params = {})
#
# Returns the count
def percolate_count(body, params = {})
response = client.get "/{index}/{type}{/id}/_percolate/count", update_params(params, body: body, action: "percolator.percolate_count", rest_api: "count_percolate")
response = client.get "/{index}/{type}{/id}/_percolate/count", update_params(params, body:, action: "percolator.percolate_count", rest_api: "count_percolate")
response.body["total"]
end

Expand Down Expand Up @@ -363,7 +363,7 @@ def termvector(params = {})
#
# Returns the response body as a hash
def multi_termvectors(body, params = {})
response = client.get "{/index}{/type}/_mtermvectors", update_params(params, {body: body, action: "docs.multi_termvectors", rest_api: "mtermvectors"}, client.version_support.es_version_8_plus?)
response = client.get "{/index}{/type}/_mtermvectors", update_params(params, {body:, action: "docs.multi_termvectors", rest_api: "mtermvectors"}, client.version_support.es_version_8_plus?)
response.body
end
alias_method :multi_term_vectors, :multi_termvectors
Expand Down Expand Up @@ -473,7 +473,7 @@ def bulk(params = {}, &block)
#
# Returns a new Scroller instance
def scroll(query, opts = {})
opts = {index: name, type: type}.merge opts
opts = {index: name, type:}.merge opts
client.scroll query, opts
end

Expand All @@ -500,7 +500,7 @@ def scroll(query, opts = {})
#
# Returns a new Scroller instance
def scan(query, opts = {})
opts = {index: name, type: type}.merge opts
opts = {index: name, type:}.merge opts
client.scan query, opts
end

Expand Down Expand Up @@ -610,7 +610,7 @@ def update_params(params, overrides = nil, delete_type = false)

# Internal: Returns a Hash containing default parameters.
def defaults
{ index: name, type: type }
{ index: name, type: }
end

# Internal: Allow params to be passed as the first argument to
Expand Down
14 changes: 7 additions & 7 deletions lib/elastomer_client/client/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def exists?(params = {})
#
# Returns the response body as a Hash
def create(body, params = {})
response = client.put "/{index}", update_params(params, body: body, action: "index.create", rest_api: "indices.create")
response = client.put "/{index}", update_params(params, body:, action: "index.create", rest_api: "indices.create")
response.body
end

Expand Down Expand Up @@ -118,7 +118,7 @@ def get_settings(params = {})
#
# Returns the response body as a Hash
def update_settings(body, params = {})
response = client.put "{/index}/_settings", update_params(params, body: body, action: "index.update_settings", rest_api: "indices.put_settings")
response = client.put "{/index}/_settings", update_params(params, body:, action: "index.update_settings", rest_api: "indices.put_settings")
response.body
end

Expand Down Expand Up @@ -147,7 +147,7 @@ def get_mapping(params = {})
#
# Returns the response body as a Hash
def update_mapping(type, body, params = {})
response = client.put "/{index}/_mapping{/type}", update_params(params, body: body, type: type, action: "index.update_mapping", rest_api: "indices.put_mapping")
response = client.put "/{index}/_mapping{/type}", update_params(params, body:, type:, action: "index.update_mapping", rest_api: "indices.put_mapping")
response.body
end
alias_method :put_mapping, :update_mapping
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_aliases(params = {})
#
# Returns the response body as a Hash
def get_alias(name, params = {})
response = client.get "/{index}/_alias/{name}", update_params(params, name: name, action: "index.get_alias", rest_api: "indices.get_alias")
response = client.get "/{index}/_alias/{name}", update_params(params, name:, action: "index.get_alias", rest_api: "indices.get_alias")
response.body
end

Expand All @@ -200,7 +200,7 @@ def get_alias(name, params = {})
#
# Returns the response body as a Hash
def add_alias(name, params = {})
response = client.put "/{index}/_alias/{name}", update_params(params, name: name, action: "index.add_alias", rest_api: "indices.put_alias")
response = client.put "/{index}/_alias/{name}", update_params(params, name:, action: "index.add_alias", rest_api: "indices.put_alias")
response.body
end

Expand All @@ -218,7 +218,7 @@ def add_alias(name, params = {})
#
# Returns the response body as a Hash
def delete_alias(name, params = {})
response = client.delete "/{index}/_alias/{name}", update_params(params, name: name, action: "index.delete_alias", rest_api: "indices.delete_alias")
response = client.delete "/{index}/_alias/{name}", update_params(params, name:, action: "index.delete_alias", rest_api: "indices.delete_alias")
response.body
end

Expand All @@ -233,7 +233,7 @@ def delete_alias(name, params = {})
# Returns the response body as a Hash
def analyze(text, params = {})
body = text.is_a?(Hash) ? text : {text: text.to_s}
response = client.get "{/index}/_analyze", update_params(params, body: body, action: "index.analyze", rest_api: "indices.analyze")
response = client.get "{/index}/_analyze", update_params(params, body:, action: "index.analyze", rest_api: "indices.analyze")
response.body
end

Expand Down
6 changes: 3 additions & 3 deletions lib/elastomer_client/client/multi_percolate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def multi_percolate(body = nil, params = nil)
raise "multi_percolate request body cannot be nil" if body.nil?
params ||= {}

response = self.post "{/index}{/type}/_mpercolate", params.merge(body: body, action: "mpercolate", rest_api: "mpercolate")
response = self.post "{/index}{/type}/_mpercolate", params.merge(body:, action: "mpercolate", rest_api: "mpercolate")
response.body
end
end
Expand Down Expand Up @@ -83,7 +83,7 @@ def initialize(client, params = {})
# Returns this MultiPercolate instance.
def percolate(doc, header = {})
add_to_actions(percolate: @params.merge(header))
add_to_actions(doc: doc)
add_to_actions(doc:)
end

# Add a percolate acount action to the multi percolate request. This
Expand All @@ -96,7 +96,7 @@ def percolate(doc, header = {})
# Returns this MultiPercolate instance.
def count(doc, header = {})
add_to_actions(count: @params.merge(header))
add_to_actions(doc: doc)
add_to_actions(doc:)
end

# Execute the multi_percolate call with the accumulated percolate actions.
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/client/multi_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def multi_search(body = nil, params = nil)
raise "multi_search request body cannot be nil" if body.nil?
params ||= {}

response = self.post "{/index}{/type}/_msearch", params.merge(body: body, action: "msearch", rest_api: "msearch")
response = self.post "{/index}{/type}/_msearch", params.merge(body:, action: "msearch", rest_api: "msearch")
response.body
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/client/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def hot_threads(params = {})
#
# Returns a new params Hash.
def update_params(params, overrides = nil)
h = { node_id: node_id }.update params
h = { node_id: }.update params
h.update overrides unless overrides.nil?
h
end
Expand Down
4 changes: 2 additions & 2 deletions lib/elastomer_client/client/percolator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(client, index_name, id)
#
# Returns the response body as a Hash
def create(body, params = {})
response = client.put("/{index}/percolator/{id}", defaults.merge(params.merge(body: body, action: "percolator.create")))
response = client.put("/{index}/percolator/{id}", defaults.merge(params.merge(body:, action: "percolator.create")))
response.body
end

Expand Down Expand Up @@ -71,7 +71,7 @@ def exists?(params = {})

# Internal: Returns a Hash containing default parameters.
def defaults
{index: index_name, id: id}
{index: index_name, id:}
end

end # Percolator
Expand Down
4 changes: 2 additions & 2 deletions lib/elastomer_client/client/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def exists?(params = {})
#
# Returns the response body as a Hash
def create(body, params = {})
response = client.put "/_snapshot/{repository}", update_params(params, body: body, action: "repository.create", rest_api: "snapshot.create_repository")
response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.create", rest_api: "snapshot.create_repository")
response.body
end

Expand Down Expand Up @@ -81,7 +81,7 @@ def status(params = {})
#
# Returns the response body as a Hash
def update(body, params = {})
response = client.put "/_snapshot/{repository}", update_params(params, body: body, action: "repository.update", rest_api: "snapshot.create_repository")
response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.update", rest_api: "snapshot.create_repository")
response.body
end

Expand Down
4 changes: 2 additions & 2 deletions lib/elastomer_client/client/rest_api_spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize
def select_params(api:, from:)
rest_api = get(api)
return from if rest_api.nil?
rest_api.select_params(from: from)
rest_api.select_params(from:)
end

# Given an API descriptor name and a single request parameter, returns
Expand All @@ -54,7 +54,7 @@ def valid_param?(api:, param:)
def select_parts(api:, from:)
rest_api = get(api)
return from if rest_api.nil?
rest_api.select_parts(from: from)
rest_api.select_parts(from:)
end

# Given an API descriptor name and a single path part, returns `true` if the
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/client/scroller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def start_scroll(opts = {})
#
# Returns the response body as a Hash.
def continue_scroll(scroll_id, scroll = "5m")
response = get "/_search/scroll", body: {scroll_id: scroll_id}, scroll: scroll, action: "search.scroll", rest_api: "scroll"
response = get "/_search/scroll", body: {scroll_id:}, scroll:, action: "search.scroll", rest_api: "scroll"
response.body
rescue RequestError => err
if err.error && err.error["caused_by"]["type"] == "search_context_missing_exception"
Expand Down
8 changes: 4 additions & 4 deletions lib/elastomer_client/client/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def exists?(params = {})
#
# Returns the response body as a Hash
def create(body = {}, params = {})
response = client.put "/_snapshot/{repository}/{snapshot}", update_params(params, body: body, action: "snapshot.create", rest_api: "snapshot.create")
response = client.put "/_snapshot/{repository}/{snapshot}", update_params(params, body:, action: "snapshot.create", rest_api: "snapshot.create")
response.body
end

Expand All @@ -69,7 +69,7 @@ def create(body = {}, params = {})
def get(params = {})
# Set snapshot name or we'll get the repository instead
snapshot = name || "_all"
response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, snapshot: snapshot, action: "snapshot.get", rest_api: "snapshot.get")
response = client.get "/_snapshot/{repository}/{snapshot}", update_params(params, snapshot:, action: "snapshot.get", rest_api: "snapshot.get")
response.body
end

Expand All @@ -92,7 +92,7 @@ def status(params = {})
#
# Returns the response body as a Hash
def restore(body = {}, params = {})
response = client.post "/_snapshot/{repository}/{snapshot}/_restore", update_params(params, body: body, action: "snapshot.restore", rest_api: "snapshot.restore")
response = client.post "/_snapshot/{repository}/{snapshot}/_restore", update_params(params, body:, action: "snapshot.restore", rest_api: "snapshot.restore")
response.body
end

Expand Down Expand Up @@ -122,7 +122,7 @@ def update_params(params, overrides = nil)

# Internal: Returns a Hash containing default parameters.
def defaults
{ repository: repository, snapshot: name }
{ repository:, snapshot: name }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/elastomer_client/client/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_by_parent_id(parent_node_id, parent_task_id, params = {})
# Returns the response body as a Hash when timeout expires or target tasks complete
# COMPATIBILITY WARNING: the response body differs between ES versions for this API
def wait_for(timeout = "10s", params = {})
self.get params.merge(wait_for_completion: true, timeout: timeout)
self.get params.merge(wait_for_completion: true, timeout:)
end

# Wait for the specified amount of time (10 seconds by default) for some task(s) to complete.
Expand All @@ -133,7 +133,7 @@ def wait_by_id(node_id, task_id, timeout = "10s", params = {})
raise ArgumentError, "invalid node ID provided: #{node_id.inspect}" if node_id.to_s.empty?
raise ArgumentError, "invalid task ID provided: #{task_id.inspect}" unless task_id.is_a?(Integer)

self.get_by_id(node_id, task_id, params.merge(wait_for_completion: true, timeout: timeout))
self.get_by_id(node_id, task_id, params.merge(wait_for_completion: true, timeout:))
end

# Cancels a task running on a particular node.
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def instrument(path, body, params)
action: params[:action],
context: params[:context],
request_body: body,
body: body # for backwards compatibility
body: # for backwards compatibility
}

::ElastomerClient::Notifications.service.instrument(NAME, payload) do
Expand Down
2 changes: 1 addition & 1 deletion test/client/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"status" => 404
}
response = Faraday::Response.new(body: body)
response = Faraday::Response.new(body:)
err = ElastomerClient::Client::Error.new(response)

assert_equal body["error"].to_s, err.message
Expand Down
2 changes: 1 addition & 1 deletion test/client/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
properties: {
title: { type: "text", analyzer: "standard" },
author: { type: "keyword" },
suggest: suggest
suggest:
}
}, true)
)
Expand Down
Loading

0 comments on commit 520c8d8

Please sign in to comment.