Skip to content

Commit 7029a09

Browse files
committed
[API] Renames functions in utils.rb from __ names
* Renames __bulkify to bulkify * Renames __escape to escape * Renames __listify to listify * Renames __pathify to pathify * Renames __extract_parts to extract_parts * Renames __rescue_from_not_found to rescue_from_not_found
1 parent bdabb56 commit 7029a09

File tree

4 files changed

+67
-170
lines changed

4 files changed

+67
-170
lines changed

elasticsearch-api/lib/elasticsearch/api/utils.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,60 +24,62 @@ module Utils
2424
# URL-escape a string
2525
#
2626
# @example
27-
# __escape('foo/bar') # => 'foo%2Fbar'
28-
# __escape('bar^bam') # => 'bar%5Ebam'
27+
# escape('foo/bar') # => 'foo%2Fbar'
28+
# escape('bar^bam') # => 'bar%5Ebam'
2929
#
3030
# @api private
31-
def __escape(string)
31+
def escape(string)
3232
return string if string == '*'
33+
3334
ERB::Util.url_encode(string.to_s)
3435
end
3536

3637
# Create a "list" of values from arguments, ignoring nil values and encoding special characters.
3738
#
3839
# @example Create a list from array
39-
# __listify(['A','B']) # => 'A,B'
40+
# listify(['A','B']) # => 'A,B'
4041
#
4142
# @example Create a list from arguments
42-
# __listify('A','B') # => 'A,B'
43+
# listify('A','B') # => 'A,B'
4344
#
4445
# @example Escape values
45-
# __listify('foo','bar^bam') # => 'foo,bar%5Ebam'
46+
# listify('foo','bar^bam') # => 'foo,bar%5Ebam'
4647
#
4748
# @example Do not escape the values
48-
# __listify('foo','bar^bam', escape: false) # => 'foo,bar^bam'
49+
# listify('foo','bar^bam', escape: false) # => 'foo,bar^bam'
4950
#
5051
# @api private
51-
def __listify(*list)
52+
def listify(*list)
5253
options = list.last.is_a?(Hash) ? list.pop : {}
5354

5455
escape = options[:escape]
55-
Array(list).
56-
flat_map { |e| e.respond_to?(:split) ? e.split(',') : e }.
57-
flatten.
58-
compact.
59-
map { |e| escape == false ? e : __escape(e) }.
60-
join(',')
56+
Array(list)
57+
.flat_map { |e| e.respond_to?(:split) ? e.split(',') : e }
58+
.flatten
59+
.compact
60+
.map { |e| escape == false ? e : escape(e) }
61+
.join(',')
6162
end
6263

6364
# Create a path (URL part) from arguments, ignoring nil values and empty strings.
6465
#
6566
# @example Create a path from array
66-
# __pathify(['foo', '', nil, 'bar']) # => 'foo/bar'
67+
# pathify(['foo', '', nil, 'bar']) # => 'foo/bar'
6768
#
6869
# @example Create a path from arguments
69-
# __pathify('foo', '', nil, 'bar') # => 'foo/bar'
70+
# pathify('foo', '', nil, 'bar') # => 'foo/bar'
7071
#
7172
# # @example Encode special characters
72-
# __pathify(['foo', 'bar^bam']) # => 'foo/bar%5Ebam'
73+
# pathify(['foo', 'bar^bam']) # => 'foo/bar%5Ebam'
7374
#
7475
# @api private
75-
def __pathify(*segments)
76-
Array(segments).flatten.
77-
compact.
78-
reject { |s| s.to_s.strip.empty? }.
79-
join('/').
80-
squeeze('/')
76+
def pathify(*segments)
77+
Array(segments)
78+
.flatten
79+
.compact
80+
.reject { |s| s.to_s.strip.empty? }
81+
.join('/')
82+
.squeeze('/')
8183
end
8284

8385
# Convert an array of payloads into Elasticsearch `header\ndata` format
@@ -86,7 +88,7 @@ def __pathify(*segments)
8688
# or the conveniency "combined" format where data is passed along with the header
8789
# in a single item.
8890
#
89-
# Elasticsearch::API::Utils.__bulkify [
91+
# Elasticsearch::API::Utils.bulkify [
9092
# { :index => { :_index => 'myindexA', :_type => 'mytype', :_id => '1', :data => { :title => 'Test' } } },
9193
# { :update => { :_index => 'myindexB', :_type => 'mytype', :_id => '2', :data => { :doc => { :title => 'Update' } } } }
9294
# ]
@@ -96,7 +98,7 @@ def __pathify(*segments)
9698
# # => {"update":{"_index":"myindexB","_type":"mytype","_id":"2"}}
9799
# # => {"doc":{"title":"Update"}}
98100
#
99-
def __bulkify(payload)
101+
def bulkify(payload)
100102
operations = %w[index create delete update]
101103

102104
case
@@ -131,7 +133,7 @@ def __bulkify(payload)
131133

132134
def process_params(arguments)
133135
arguments = Hash[arguments] unless arguments.is_a?(Hash)
134-
Hash[arguments.map { |k, v| v.is_a?(Array) ? [k, __listify(v, { escape: false })] : [k, v] }] # Listify Arrays
136+
Hash[arguments.map { |k, v| v.is_a?(Array) ? [k, listify(v, { escape: false })] : [k, v] }] # Listify Arrays
135137
end
136138

137139
# Extracts the valid parts of the URL from the arguments
@@ -144,14 +146,14 @@ def process_params(arguments)
144146
# @return [Array<String>] Valid parts of the URL as an array of strings
145147
#
146148
# @example Extract parts
147-
# __extract_parts { :foo => true }, [:foo, :bar]
149+
# extract_parts { :foo => true }, [:foo, :bar]
148150
# # => [:foo]
149151
#
150152
#
151153
# @api private
152154
#
153-
def __extract_parts(arguments, valid_parts=[])
154-
Hash[arguments].reduce([]) { |sum, item| k, v = item; v.is_a?(TrueClass) ? sum << k.to_s : sum << v }
155+
def extract_parts(arguments, _valid_parts = [])
156+
Hash[arguments].reduce([]) { |sum, item| k, v = item; v.is_a?(TrueClass) ? sum << k.to_s : sum << v }
155157
end
156158

157159
# Calls the given block, rescuing from `StandardError`.
@@ -165,7 +167,7 @@ def __extract_parts(arguments, valid_parts=[])
165167
#
166168
# @api private
167169
#
168-
def __rescue_from_not_found(&block)
170+
def rescue_from_not_found(&block)
169171
yield
170172
rescue StandardError => e
171173
if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found/i

0 commit comments

Comments
 (0)