Class: ElasticsearchDslBuilder::DSL::Search::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch_dsl_builder/dsl/search/script.rb

Instance Method Summary collapse

Instance Method Details

#file(file) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 25

def file(file)
  raise ArgumentError, 'can be inline or file script. not both' if @source
  raise ArgumentError, 'file must be a String' unless file.instance_of?(String)
  @file = file
  self
end

#inline(inline) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 18

def inline(inline)
  raise ArgumentError, 'can be inline or file script. not both' if @file
  raise ArgumentError, 'inline must be a String' unless inline.instance_of?(String)
  @inline = inline
  self
end

#lang(lang) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 5

def lang(lang)
  raise ArgumentError, 'lang must be a String' unless lang.instance_of?(String)
  @lang = lang
  self
end

#params(params) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 32

def params(params)
  raise ArgumentError, 'params must be a hash' unless params.instance_of?(Hash)
  @params = params
  self
end

#source(source) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 11

def source(source)
  raise ArgumentError, 'can be inline or file script. not both' if @file
  raise ArgumentError, 'source must be a String' unless source.instance_of?(String)
  @source = source
  self
end

#to_hashObject



38
39
40
41
42
43
44
45
46
# File 'lib/elasticsearch_dsl_builder/dsl/search/script.rb', line 38

def to_hash
  script = {}
  @lang ||= 'painless'
  script.update(lang: @lang, source: @source) if @source
  script.update(lang: @lang, inline: @inline) if @inline
  script.update(file: @file) if @file
  script.update(params: @params) if @params
  script
end