Method: Elasticsearch::API::Utils#__listify

Defined in:
lib/elasticsearch/api/utils.rb

#__listify(*list) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a “list” of values from arguments, ignoring nil values and encoding special characters.

Examples:

Create a list from array

__listify(['A','B']) # => 'A,B'

Create a list from arguments

__listify('A','B') # => 'A,B'

Escape values

__listify('foo','bar^bam') # => 'foo,bar%5Ebam'

Do not escape the values

__listify('foo','bar^bam', escape: false) # => 'foo,bar^bam'
[View source]

51
52
53
54
55
56
57
58
59
60
61
# File 'lib/elasticsearch/api/utils.rb', line 51

def __listify(*list)
  options = list.last.is_a?(Hash) ? list.pop : {}

  escape = options[:escape]
  Array(list).
    flat_map { |e| e.respond_to?(:split) ? e.split(',') : e }.
    flatten.
    compact.
    map { |e| escape == false ? e : __escape(e) }.
    join(',')
end