@@ -24,60 +24,62 @@ module Utils
24
24
# URL-escape a string
25
25
#
26
26
# @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'
29
29
#
30
30
# @api private
31
- def __escape ( string )
31
+ def escape ( string )
32
32
return string if string == '*'
33
+
33
34
ERB ::Util . url_encode ( string . to_s )
34
35
end
35
36
36
37
# Create a "list" of values from arguments, ignoring nil values and encoding special characters.
37
38
#
38
39
# @example Create a list from array
39
- # __listify (['A','B']) # => 'A,B'
40
+ # listify (['A','B']) # => 'A,B'
40
41
#
41
42
# @example Create a list from arguments
42
- # __listify ('A','B') # => 'A,B'
43
+ # listify ('A','B') # => 'A,B'
43
44
#
44
45
# @example Escape values
45
- # __listify ('foo','bar^bam') # => 'foo,bar%5Ebam'
46
+ # listify ('foo','bar^bam') # => 'foo,bar%5Ebam'
46
47
#
47
48
# @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'
49
50
#
50
51
# @api private
51
- def __listify ( *list )
52
+ def listify ( *list )
52
53
options = list . last . is_a? ( Hash ) ? list . pop : { }
53
54
54
55
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 ( ',' )
61
62
end
62
63
63
64
# Create a path (URL part) from arguments, ignoring nil values and empty strings.
64
65
#
65
66
# @example Create a path from array
66
- # __pathify (['foo', '', nil, 'bar']) # => 'foo/bar'
67
+ # pathify (['foo', '', nil, 'bar']) # => 'foo/bar'
67
68
#
68
69
# @example Create a path from arguments
69
- # __pathify ('foo', '', nil, 'bar') # => 'foo/bar'
70
+ # pathify ('foo', '', nil, 'bar') # => 'foo/bar'
70
71
#
71
72
# # @example Encode special characters
72
- # __pathify (['foo', 'bar^bam']) # => 'foo/bar%5Ebam'
73
+ # pathify (['foo', 'bar^bam']) # => 'foo/bar%5Ebam'
73
74
#
74
75
# @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 ( '/' )
81
83
end
82
84
83
85
# Convert an array of payloads into Elasticsearch `header\ndata` format
@@ -86,7 +88,7 @@ def __pathify(*segments)
86
88
# or the conveniency "combined" format where data is passed along with the header
87
89
# in a single item.
88
90
#
89
- # Elasticsearch::API::Utils.__bulkify [
91
+ # Elasticsearch::API::Utils.bulkify [
90
92
# { :index => { :_index => 'myindexA', :_type => 'mytype', :_id => '1', :data => { :title => 'Test' } } },
91
93
# { :update => { :_index => 'myindexB', :_type => 'mytype', :_id => '2', :data => { :doc => { :title => 'Update' } } } }
92
94
# ]
@@ -96,7 +98,7 @@ def __pathify(*segments)
96
98
# # => {"update":{"_index":"myindexB","_type":"mytype","_id":"2"}}
97
99
# # => {"doc":{"title":"Update"}}
98
100
#
99
- def __bulkify ( payload )
101
+ def bulkify ( payload )
100
102
operations = %w[ index create delete update ]
101
103
102
104
case
@@ -131,7 +133,7 @@ def __bulkify(payload)
131
133
132
134
def process_params ( arguments )
133
135
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
135
137
end
136
138
137
139
# Extracts the valid parts of the URL from the arguments
@@ -144,14 +146,14 @@ def process_params(arguments)
144
146
# @return [Array<String>] Valid parts of the URL as an array of strings
145
147
#
146
148
# @example Extract parts
147
- # __extract_parts { :foo => true }, [:foo, :bar]
149
+ # extract_parts { :foo => true }, [:foo, :bar]
148
150
# # => [:foo]
149
151
#
150
152
#
151
153
# @api private
152
154
#
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 }
155
157
end
156
158
157
159
# Calls the given block, rescuing from `StandardError`.
@@ -165,7 +167,7 @@ def __extract_parts(arguments, valid_parts=[])
165
167
#
166
168
# @api private
167
169
#
168
- def __rescue_from_not_found ( &block )
170
+ def rescue_from_not_found ( &block )
169
171
yield
170
172
rescue StandardError => e
171
173
if e . class . to_s =~ /NotFound/ || e . message =~ /Not\s *Found/i
0 commit comments